akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
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;}

const int MAX_N=500;
const int MAX_A=100000;

int N,K;
int A[MAX_N+5];

int sum;
int ans;

vector<int> divisor(int n) {
    vector<int> res;
    for (int i=1;i*i<=n;i++) {
        res.push_back(i);
        if(n%i==0)res.push_back(n/i);
    }
    sort(res.begin(),res.end());
    return res;
}

bool check(int m){
    vector<int> d;
    for(int i=0;i<N;++i)d.push_back(A[i]%m);
    sort(d.begin(),d.end());
    int l=0,r=N-1;
    int cnt=0;
    while(true){
        if(r==l){
            if(d[l]%m==0)return true;
            else return false;
        }
        if(cnt>K)return false;
        if(d[l]%m==0)l++;
        else if(d[r]%m==0)r--;
        else {
            int cost=min(d[l],m-d[r]);
            cnt+=cost;
            d[l]-=cost;
            d[r]+=cost;
        }
    }
}

signed main(){
    cin>>N>>K;
    for(int i=0;i<N;++i){
        cin>>A[i];
        sum+=A[i];
    }
    for(auto m:divisor(sum)){
        if(check(m))ans=m;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)

#define mp make_pair
#define fi first
#define se second

#define bit(n) (1LL<<(n))

i64 N,K,S;

void Main()
{
  cin >> N >> K >> S;
  
  i64 t;
  if(S>pow(10,8)) t= 1;
  else t=pow(10,9);

  rep(i,N){
    if(i<K) cout << S;
    else cout << t;
    if(i!=N-1) cout << " ";
    else cout << endl;
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 1280
n = int(input())

#モンスターiの体力:mon[i]
mon = list(map(int, input().split()))


zero = 0
while mon.count(0) != (n-1):
    mon.sort()
    min = mon[zero]
    tei = zero + 1
    for i in range(tei,n):
        mon[i] = mon[i] % min
        if mon[i] == 0:
            zero += 1
mon.sort()
print(mon[zero])


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(3*N);
    for ( int i = 0; i < 3*N; i++ ) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        ans += A[N+2*i];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
/* Author : Ravikumar Navale */
#define fastIo() ios_base :: sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pb push_back
#define endl  "\n"
typedef long long int ll;
vector<pair<ll,ll> >v1, v2, v3;
const ll MOD = 1e9 + 7;
const double peek = 1e7 ;

int main()
{
    fastIo();
    ll N, W;
    cin>> N >>W;
    ll val[N+1];
    ll wt[N+1];
    for(ll i=0 ; i < N ; i++)
        cin >> wt[i]>>val[i];
   ll i, w; 
   ll K[N+1][W+1]; 
    
  
  
   for (i = 0; i <= N; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   cout << K[N][W]; 

    
    
}

Measured memory_bytes: 79104
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int l=sc.nextInt();
  		int min=0;
  		int total=0;
		
  		int[] aji=new int[n];
		for(int c=0;c<n;c++){
    		aji[c]=l+(c+1)-1;
            total+=aji[c];
            if(Math.abs(aji[min])>=Math.abs(aji[c])){
            	min=c;
            }
    	}
      

    	System.out.println(total-aji[min]);
    }
}



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

int main(){
  int length, width;
  while(1){
    cin >> length >> width;
    if(length == 0 || width == 0){
      break;
    }
    for(int i = 0; i < length; i++){
      for(int j = 0; j < width; j++){
        if(((i + j) % 2) == 0){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ll mod=1e9+7;
const ld PI = 2 * acos(0.0);
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
	if(b==0)
		return 1;
	ll d=power(a,b/2,m);
	d=(d*d)%m;
	if(b&1)
		d=(d*a)%m;
	return d;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int tt=1;
	int k;cin>>k;
	int ans=0;
	ff(i,k)
	{
		ff(j,k)
		{
			int g=__gcd(i,j);
			ff(k1,k)
				ans+=__gcd(g,k1);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3600
n,k  = map(int,input().split())
a = list(map(int,input().split()))

k = k%1000000007

tent  = [0 for i in range(n)]
ind = [0 for i in range(n)]

for i in range(n):
        al = 0
        bl = 0
        for j in range(n):
                if i < j and a[i] > a[j]:
                        al += 1
                if a[i] > a[j]:
                        bl += 1

        tent[i] = al
        ind[i] = bl

#print(tent)
#print(ind)

ans = 0

for i in range(n):
        ans += tent[i]*k
        ans +=(k*(k-1)//2)*ind[i]
        #print("今の"+str(ans))
        ans = ans%1000000007
print(ans%1000000007)

Measured memory_bytes: 42476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  string C = "";
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    
    if (S=="Y") {
      C = "Four";
      break;
    }
  }
  
  if (C=="") {
    C="Three";
  }
  
  cout << C << endl;
}

Measured memory_bytes: 3620
import numpy as np

N = int(input())
s = input()
w = np.array(list(map(lambda x: 1 if x == 'W' else 0, s)))
e = np.array(list(map(lambda x: 1 if x == 'E' else 0, s)))
w = np.cumsum(w)
# w = np.add.accumulate(w)
e = e[::-1]
e = np.cumsum(e)
# e = np.add.accumulate(e)
e = e[::-1]
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
print(min(ans))

Measured memory_bytes: 33108
#include <stdio.h>
#include <string.h>
int main()
{
    char x[101], y[101], s[201];
    scanf("%s", x);
    scanf("%s", y);

    for (int i = 0; i < strlen(x); i++)
    {
        s[i] = x[i];
        s[strlen(x) + i] = x[i];
    }
    s[2 * strlen(x)] = '\0';
    if (strstr(s, y) != NULL)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 2112
fun main(arr:Array<String>) {
    var num = readLine()!!.toLong()
    var idx = 1
    val flag = mutableMapOf<Long, Int>()
    while (idx >= 0) {
        flag[num]?.let {
            println(idx)
            return
        }
        flag[num] = idx
        if(num % 2  == 0L) {
            num /= 2
        } else {
            num = num*3+1
        }
        idx++
    }
}


Measured memory_bytes: 33396
n=int(input())
arr=list(map(int,input().split()))
arr=[[arr[i],i+1] for i in range(n)]
mins=[10**18,0]
maxs=[-10**18,0]
flag=True
for i in range(n):
  if arr[i][0]<mins[0]:
    mins=[arr[i][0],arr[i][1]]
  if arr[i][0]>maxs[0]:
    maxs=[arr[i][0],arr[i][1]]
cnt=0
ans=[]
if maxs[0]<0:
  for i in range(n):
    flag=False
elif mins[0]>=0:
  pass
else:
  if abs(mins[0])>maxs[0]:
    flag=False
    for i in range(n):
      if arr[i][0]>0:
        arr[i][0]+=mins[0]
        cnt+=1
        ans.append([mins[1],arr[i][1]])
  else:
    for i in range(n):
      if arr[i][0]<0:
        arr[i][0]+=maxs[0]
        cnt+=1
        ans.append([maxs[1],arr[i][1]])
rows=[]
tmp=[[arr[0][0],arr[0][1]]]
for i in range(1,n):
  if arr[i-1][0]<=arr[i][0]:
    tmp.append([arr[i][0],arr[i][1]])
  else:
    rows.append(tmp)
    tmp=[[arr[i][0],arr[i][1]]]
if len(tmp)!=0:
  rows.append(tmp)
if flag==True:
  for i in range(len(rows)-1):
    if len(rows[i])==1:
      if len(rows[i+1])==1:
        rows[i+1][0][0]+=rows[i][0][0]
        ans.append([rows[i][0][1],rows[i+1][0][1]])
  for i in range(len(rows)-1):
    if len(rows[i])==1:
      if len(rows[i+1])==1:
        continue
      else:
        for j in range(len(rows[i+1])):
          rows[i+1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i+1][j][1]])
    else:
      if len(rows[i+1])==1:
        for j in range(i+1,len(rows)):
          if len(rows[j])==1:
            rows[j][0][0]+=rows[i][-1][0]
            ans.append([rows[i][-1][1],rows[j][0][1]])
          else:
            break
      else:
        for j in range(len(rows[i+1])):
          rows[i+1][j][0]+=rows[i][-1][0]
          ans.append([rows[i][-1][1],rows[i+1][j][1]])
else:
  for i in range(len(rows)-1,0,-1):
    if len(rows[i])==1:
      if len(rows[i-1])==1:
        rows[i-1][0][0]+=rows[i][0][0]
        ans.append([rows[i][0][1],rows[i-1][0][1]])
  for i in range(len(rows)-1,0,-1):
    if len(rows[i])==1:
      if len(rows[i-1])==1:
        continue
      else:
        for j in range(len(rows[i-1])):
          rows[i-1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i-1][j][1]])
    else:
      if len(rows[i-1])==1:
        for j in range(i-1,-1,-1):
          if len(rows[j])==1:
            rows[j][0][0]+=rows[i][0][0]
            ans.append([rows[i][0][1],rows[j][0][1]])
          else:
            break
      else:
        for j in range(len(rows[i-1])):
          rows[i-1][j][0]+=rows[i][0][0]
          ans.append([rows[i][0][1],rows[i-1][j][1]])
print(len(ans))
for i in range(len(ans)):
  print(*ans[i])

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

typedef long long ll;
const int maxn = 5e5 + 5, mod = 998244353;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

void dec(int &a, int b) {a -= b; if (a < 0) a += mod;}

int fpow(int x, int k)
{
	int res = 1;
	while (k) {
		if (k & 1) res = (ll)res * x % mod;
		k >>= 1; x = (ll)x * x % mod;
	}
	return res;
}

int n, m, fac[maxn], ifac[maxn];

int C(int m, int n)
{
	if (n > m) return 0;
	return (ll)fac[m] * ifac[n] % mod * ifac[m - n] % mod;
}

int main()
{
	n = gi(); m = gi();
	if (m < n) return puts("0"), 0;
	
	fac[0] = 1;
	for (int i = 1; i <= m; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	ifac[m] = fpow(fac[m], mod - 2);
	for (int i = m - 1; ~i; --i) ifac[i] = (ll)ifac[i + 1] * (i + 1) % mod;

	int ans = 0;
	for (int R = 0, B; R <= m; ++R) {
		B = m - R;
		if (R == B) --B;
		int L = R - B;
		if (L < 0 || (n - L) > B) continue;
		int T = B - (n - L);
		ans = (ans + C(R + B, R)) % mod;
		if (L < n) dec(ans, C(R + B, R + T + 1));
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 4096
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

ans = []
import itertools
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for a, b, c, d in abcd:
        if A[b-1] - A[a-1] == c:
            tmp += d
    ans.append(tmp)
print(max(ans))

Measured memory_bytes: 12532
n=int(input())
A=list()
for i in range(n):
    a,b=map(int,input().split())
    c=abs(a-b)
    A.append(c)
for i in range(n-2):
    p,q,r=A[i],A[i+1],A[i+2]
    s=p+q+r
    if s==0:
        print('Yes')
        break
else:
    print('No')    

Measured memory_bytes: 62468
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=100;
typedef pair<string,ll> P;
P res[MAX_N];
ll N;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N){
		string s;
		ll p;
		cin>>s>>p;
		res[i]=P(s,-p);
	}
	vector<ll> ans(N);
	REP(i,N)ans[i]=i;
	sort(ans.begin(),ans.end(),[](ll a,ll b){
		return res[a]<res[b];
	});
	REP(i,N){
		cout<<ans[i]+1<<endl;
	}
}

Measured memory_bytes: 256
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()

ans = 0
for i in range(1,N):
  a = N - i
  if a != i:
    ans += 1
print(ans//2)

Measured memory_bytes: 40268
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	int[] ary = new int[n];
    	long sum = 0;
    	for(int i = 0; i < n; i++){
    		ary[i] += sc.nextInt();
    	}
    	sc.close();
    	Arrays.sort(ary);
    	int len = ary.length;
    	if(k > len){
    		System.out.println(sum);
    		return;
    	}
    	int t = n-1;
    	for(int i = 0; i < k; i++){
    		ary[t] = 0;
    		t--;
    	}
    	for(int i = 0; i < len; i++){
    		sum += ary[i];
    	}
    	System.out.println(sum);
    }
}

Measured memory_bytes: 64972
# -*- coding: utf-8 -*-

n = int(input())
a = [list(map(int, input().split())) for i in range(2)]
goal = (1, n-1)
def down_right(x, y, candy):
    x += 1
    candy += a[x][y]
    if y != n-1:
        for i in range(n-y-1):
            y += 1
            candy += a[x][y]
    return candy

x = 0
y = 0
hist_candy = a[x][y]
max_candy = down_right(0,0, hist_candy)
for i in range(n-1):
    if (x,y) != goal:
        y += 1
        hist_candy += a[x][y]
        temp = down_right(x,y, hist_candy)
        if max_candy < temp:
            max_candy = temp
if max_candy < hist_candy:
    print(hist_candy)
print(max_candy)


Measured memory_bytes: 3064
#include <cstdio>
#define N 1005

int n, m;
int a[N];

int main() {
    scanf("%d%d", &n, &m);
    double sum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        sum += a[i];
    }
    sum /= m << 2;
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] >= sum)
            ++cnt;
    if (cnt >= m) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
import annotation.tailrec

object Main extends App {
  val an = 55555
  val isPrime = eratos(an)
  val n =  in.readInt
  val seq = mu.ListBuffer.empty[Int]

  @tailrec
  def rec(cnt:Int, num:Int):Unit = {
    if(cnt == n) return
    else if(num % 5 == 1 && isPrime(num)){
      seq += num
      rec(cnt+1, num+2)
    }
    else rec(cnt, num+2)
  }
  rec(0,11)

  val ans = seq.mkString(" ")
  println(ans)

  def eratos(n:Int):Array[Boolean] = {
    val ret = Array.fill(n+1)(true)
    ret(0) = false
    ret(1) = false
    for(i <- 2 to n) {
      if(ret(i)) {
        var j = i + i
        while(j <= n) {
          ret(j) = false
          j += i
        }
      }
    }
    ret
  }
}

Measured memory_bytes: 25928
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	ll N,M;
    string S,T;
  	cin>>N>>M;
  	cin>>S;
  	cin>>T;
  	ll lcm=N*M/gcd(N,M);
  	ll good = 1;
  
  	if(S[0]!=T[0]) good=0; 
  	rep(i,gcd(N,M)-1){
     	if(S[i*N/gcd(N,M)]!=T[i*M/gcd(N,M)]) good=0; 
    }
  
  	if(good) cout<<lcm<<endl;
  	else cout<<-1<<endl;
}

Measured memory_bytes: 3764
#include <iostream>

using namespace std;
int main(){
	int a,b,c,t;
	cin>>a>>b>>c;
	t=100*a+10*b+c;
	if(t%4==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
block = list(map(int, input().split()))
block.reverse()
for i in range(len(block)):
    if i == len(block)-1:
        break
    if block[i] >= block[i+1]:
        continue
    elif block[i] < block[i+1] - 1:
        print("No")
        exit(0)
    else:
        block[i+1] -= 1
print("Yes")

Measured memory_bytes: 14396
fun main(args: Array<String>) {

    var tmpLine = readLine()

    
    val result = experiment(tmpLine!!)

    println(result)
}

fun experiment(input: String) : String {

    val n = input.toLong()-1
    var result = ""
    val atozList = mutableListOf<String>()
    for (alphabet in 'a'..'z') {
        atozList.add("${alphabet}")
    }



    val amari1 = n % 26 // 0-25 0 の場合は+26 -1 + 2
    val sho1 = (n - amari1) / 26
    // val idx1 = if (amari1 == 0L) 26 else amari1.toInt()
    val idx1 = amari1.toInt()
    result = atozList[idx1] + result
    if (sho1 < 1L) return result

    var nextVal = sho1

    while (nextVal > 0) {
        nextVal = nextVal -1
        val amari2 = nextVal % 26
        // val idx2 = if (amari2 == 0L) 26 else amari2.toInt()
        val idx2 = amari2.toInt()
        val sho2 = (nextVal - amari2) / 26
        result = atozList[idx2] + result
        if (sho2 < 1L) return result
        nextVal = sho2
    } 

    // var nextVal2 = sho1
    // val amari2 = nextVal2 % 26
    // val sho2 = (nextVal2 - amari2) / 26
    // result = atozList[amari2-1] + result
    // if (sho2 == 0) return result

    // var nextVal3 = sho2
    // val amari3 = nextVal3 % 26
    // val sho3 = (nextVal3 - amari3) / 26
    // result = atozList[amari3-1] + result
    // if (sho3 == 0) return result

    // var nextVal4 = sho3
    // val amari4 = nextVal4 % 26
    // val sho4 = (nextVal4 - amari4) / 26
    // result = atozList[amari4-1] + result
    // if (sho4 == 0) return result

    // var nextVal5 = sho4
    // val amari5 = nextVal5 % 26
    // val sho5 = (nextVal5 - amari5) / 26
    // result = atozList[amari5-1] + result
    // if (sho5 == 0) return result

    // var nextVal6 = sho5
    // val amari6 = nextVal6 % 26
    // val sho6 = (nextVal6 - amari6) / 26
    // result = atozList[amari6-1] + result
    // if (sho6 == 0) return result

    return result
}


Measured memory_bytes: 34512
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll a[maxn],b[maxn],dp[maxn][maxn],n,m;
const ll mod=1000000007;

int main()
{
	n=read(); m=read();
	for(int i=1;i<=n;i++) a[i]=read(),dp[i][0]=1;
	for(int i=1;i<=m;i++) b[i]=read(),dp[0][i]=1; dp[0][0]=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
		if(a[i]==b[j]) dp[i][j]+=dp[i-1][j-1]; dp[i][j]=(dp[i][j]+mod)%mod;
	}
	cout<<dp[n][m]<<endl;
	return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[1];
int size=1;
int m=2;
#define N 101
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)

int main()
{
    fast;

    char c;
    cin>>c;
    if(isupper(c))
        cout<<"A";
    else
        cout<<"a";



}

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

int P,Q,A,N;

int accum(int p,int q,int depth,int dono,int prd){
  if(p==0)return 1;
  int res=0;
  for(int i=dono;prd*i<=A;i++){
    if((N-depth)*q<i*p)break;
    if(p*i<q)continue;
    res+=accum(p*i-q,q*i,depth+1,i,prd*i);
    //cout<<depth<<" "<<res<<endl;
  }
  return res;
}

int main(){
  while(cin>>P>>Q>>A>>N,A) cout<<accum(P,Q,0,1,1)<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
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;}


// initialization
const int MAX = int(2e5)+10;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

int main() {
  // initialize
  COMinit();

  ll n, m, k;
  cin >> n >> m >> k;

  ll ans = 0;
  ll a = (((m*m)%MOD) * COM(n+1, 3)) % MOD;
  ll b = (((n*n)%MOD) * COM(m+1, 3)) % MOD;
  ans = (a + b) % MOD;
  // ans *= COM(k, 2);
  // ans %= MOD;
  ans *= COM(m*n-2, k-2);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	string s,t;
	cin >> s >> t;
	int n=s.size(),m=t.size();
	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));
	rep(i,1,n+1)
		rep(j,1,m+1)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(s[i-1] == t[j-1])
				dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
		}		
	string ans;
	int i=n;int j=m;
	        while(i>0 && j>0){
	        if(s[i-1]==t[j-1])
	        {
	            ans+=s[i-1];
	            i--;
	            j--;
	        }
	        else
	        {
	            if(dp[i-1][j]>dp[i][j-1])
	            i--;
	            else 
	            j--;
	        }
	    }
	        
	reverse(all(ans));
	cout <<ans ;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 74004
#include<iostream>
using namespace std;
int main(void){
  int a[12]={1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int b, c;
  cin >> b >> c;
  a[b-1] == a[c-1] ? cout << "Yes" << endl : cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,a[300];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  cout<<a[n-1]-a[0]<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  ll n,m;
  sl(n);
  sl(m);
  ll k1 = m*1900 + (n-m)*100;
  ll k2 = k1*pow(2,m);
  cout << k2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int ans = 0;
  string S;
  cin >> S;
  if (S == "RRR")
    cout << 3 << endl;
  else if (S == "SSS")
    cout << 0 << endl;
  else if (S == "RRS" || S == "SRR")
    cout << 2 << endl;
  else
    cout << 1 << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int n,l;
	string s[182] = {};
	cin >> n >> l;
	for (int i=0;i<n;i++) cin >> s[i];
	sort (s,s+n);
	for (int i=0;i<n;i++) cout << s[i];
}



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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
const int INF = 1145141919;

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

    int N;
    std::cin >> N;
    int h[N];
    for(int i=0; i<N; ++i){
        std::cin >> h[i];
    }

    int dp[N];
    for(int i=0; i<N; ++i) dp[i]=INF;
    dp[0] = 0;
    for(int i=1; i<N; ++i){
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1){
            chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
        }
    }

    std::cout << dp[N-1];

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int[] str = new int[5];
		for(int i=0; i<5; i++){
			str[i] = scan.nextInt();
		}
		Arrays.sort(str);
		System.out.println(str[4] + " " + str[3] + " " + str[2] + " " + str[1] + " " + str[0]);
	}
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
  ll left = MOD-2;
  ll ans = 1;
  ll ks = a;
  while(left > 0)
  {
    if(left%2 == 1)
    {
      ans = ans*ks%MOD;
    }
    left /= 2;
    ks = ks*ks%MOD;
  }
  return ans;
}

int main()
{
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  int i;
  rep(i,n) cin >> a[i];
  vector<pair<ll,ll>> p(n);
  rep(i,n)
  {
    if(a[i] >= 0)
    {
      p[i] = make_pair(a[i],1);
    }
    else
    {
      p[i] = make_pair(-a[i],-1);
    }
  }
  sort(all(p));
  reverse(all(p));
  int cnt = 0;
  ll kans = 1;
  rep(i,k)
  {
    if(p[i].second == -1)
    {
      cnt++;
    }
    kans = kans*p[i].first;
    kans %= MOD;
  }
  ll ans = -1;
  if(cnt%2 == 0 || kans == 0) ans = kans;
  else
  {
    bool ch = false;
    int fp = -1;
    int fn = -1;
    rep(i,k)
    {
      if(p[i].second == 1)
      {
        fp = i;
      }
      else if(p[i].second == -1)
      {
        fn = i;
      }
    }
    int kp,kn;
    kp = -1;
    kn = -1;
    for(i=k;i<n;i++)
    {
      if(p[i].first == 0)
      { 
        break;
      }
      if(p[i].second == 1 && fn != -1 && kp == -1)
      {
        kp = i;
        ch = true;
      }
      else if(p[i].second == -1 && fp != -1 && kn == -1)
      {
        kn = i;
        ch = true;
      }
    }
    if(kp > 0 || kn > 0)
    {
      if(kp > 0 && kn > 0)
      {
        if(p[kp].first*p[fp].first >= p[kn].first*p[fn].first)
        {
          kans = kans*p[kp].first%MOD;
          kans = kans*mod_inv(p[fn].first)%MOD;
        }
        else
        {
          kans = kans*p[kn].first%MOD;
          kans = kans*mod_inv(p[fp].first)%MOD;
        } 
      }
      else if(kp > 0)
      {
        kans = kans*p[kp].first%MOD;
        kans = kans*mod_inv(p[fn].first)%MOD;
      }
      else if(kn > 0)
      {
        kans = kans*p[kn].first%MOD;
        kans = kans*mod_inv(p[fp].first)%MOD;
      }
      ans = kans;
    }
    else
    {
      kans = 1;
      rep(i,k)
      {
        kans = kans*p[n-1-i].first%MOD;
      }
      ans = MOD-kans;
      ans %= MOD;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 7904
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<pair<string, int>> st(N);
    REP(i, 0, N) {
        cin >> st[i].first >> st[i].second;
    }

    string X; cin >> X;
    bool ok = false;
    int ans = 0;
    REP(i, 0, N) {
        if (ok) ans += st[i].second;
        if (st[i].first == X) ok = true;
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Working program with FastReader 
import java.io.*; 

import java.util.*; 
 

public class Main 
{ 
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

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

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

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

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	} 

	public static void main(String[] args) 
	{ 
		FastReader sc=new FastReader(); 
		int d = sc.nextInt(); 
		int t= sc.nextInt();
		int s=sc.nextInt();
		long dist=t*s;
		if(dist>=d)
		System.out.println("Yes");
		else
		System.out.println("No");
	} 
} 


Measured memory_bytes: 32672
from itertools import groupby
s = input()
k = int(input())
x = y = 0
g = [len(list(v)) for k,v in groupby(s)]
#print(g)
for c in g:
    x += c // 2
if s[-1] == s[0]:
    if g[-1] % 2 == 0 or g[0] % 2 == 0:
        pass
    elif len(s) == 1:
        y = k//2
    elif len(s) == g[0]:
        y = k//2
    else:
        y = k-1
print(x * k + y)


Measured memory_bytes: 3064
S = input()


def f(s, n):
    # print(format(n, "b"))
    r = 0
    a = 0
    for i in range(len(s) - 1):
        if n & (1 << i) == 0:
            a += int(s[i])
            a *= 10
        else:
            a += int(s[i])
            r += a
            a = 0

    a += int(s[len(s) - 1])
    r += a

    return r


N = (1 << (len(S) - 1))
ans = 0
for n in range(N):
    a = f(S, n)
    # print(a)
    ans += a

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
using namespace std;

typedef long long ll;

const int N=2e5+5;
const ll INF=1e18;
int a[N];
int main() {
   int n;
   scanf("%d", &n);
   ll sum=0;
   rep(i,n) {
      scanf("%d", &a[i]);
      sum+=a[i];
   }

   // initial first cut at 0
   //         second cut at 1
   //         third cut at 2
   int fi=0, se=1, thi=2;
   ll w=a[0],x=a[1],y=a[2],z=sum-w-x-y;
   ll ans=INF;
   for ( ; se+2<n; se++) {
      // printf("%lld %lld %lld %lld\n", w, x, y, z);
      while ( fi+1<se && abs(w+a[fi+1]-x+a[fi+1])<abs(w-x) ) {
         fi++; w+=a[fi]; x-=a[fi];
      }
      while ( thi+1<n && abs(y+a[thi+1]-z+a[thi+1])<abs(y-z) ) {
         thi++; y+=a[thi]; z-=a[thi];
      }
      ll mx=max({w,x,y,z});
      ll mi=min({w,x,y,z});
      ans=min(ans,mx-mi);
      x+=a[se+1];
      y-=a[se+1];
   }
   printf("%lld\n",ans);
   return 0;
}



Measured memory_bytes: 1152
import sys
e=sys.stdin
while 1:
 a=b=0;n=int(e.readline())
 if n==0:break
 for i in[0]*n:
  s,t=map(int,e.readline().split())
  if s>t:a+=s+t
  elif s<t:b+=s+t
  else:a+=s;b+=t
 print(a,b)


Measured memory_bytes: 5720
N = int(input())
l = [int(x) for x in input().split()]
num = [0] * N
C = 0
for i in range(N):
  num[l[i] - 1] += 1
for i in range(N):
  C += num[i] * (num[i] - 1) // 2
for i in range(N):
  print(C - num[l[i]-1] + 1)

Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    rep(i, 1, 10) {
        int tmp = INF;
        if (n % i == 0) tmp = n / i;
        if (tmp <= 9) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        int N;
        int M;
        int i = 0;
        int Sum = 0;


        Scanner scan = new Scanner(System.in);
        N = scan.nextInt();

        M = scan.nextInt();

        int[] A = new int[M];

        while (i < M) {
           
            A[i] = scan.nextInt();
            Sum = Sum + A[i];
            i = i + 1;
        }
        int Days = N - Sum;

        if (Days < 0) {
            System.out.println("-1");
        } else {
            System.out.println(Days);

        }
    }
}


Measured memory_bytes: 46228
<?php
class Dice{
  public $label=[1,2,3,4,5,6];#index+1????????¢?????????
  public $pos=[0,1,2];#?????¢,?????¢,??\??¢???index ???????????¢???5-index
  function __construct($sLabel){
    $this->label=explode(' ',$sLabel,6);
  }
  function move($s){
    $x=$this->pos[0];
    if($s=='E'){
      $this->pos[0]=5-$this->pos[2];
      $this->pos[2]=$x;
    }
    elseif($s=='W'){
      $this->pos[0]=$this->pos[2];
      $this->pos[2]=5-$x;
    }
    elseif($s=='N'){
      $this->pos[0]=$this->pos[1];
      $this->pos[1]=5-$x;
    }
    elseif($s=='S'){
      $this->pos[0]=5-$this->pos[1];
      $this->pos[1]=$x;
    }
  }
  function top(){
    return $this->label[$this->pos[0]];
  }
}

$dice=new Dice(trim(fgets(STDIN)));
$move=str_split(trim(fgets(STDIN)));
foreach($move as $m) $dice->move($m);
echo $dice->top();
?>

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

int main(void){
    string s,t;
    cin >> s >> t;
    reverse(s.begin(),s.end());
    reverse(t.begin(),t.end());

    int pos = -1;
    for(int i=0;i<s.size();i++){
        bool ok = true;
        for(int j=0;j<t.size();j++){
            if(i+j>=s.size()){ok = false; break;}
            if(s[i+j]=='?') continue;
            if(t[j]!=s[i+j]){ok = false; break;}
        }
        if(ok){
            pos = i;
            break;
        }
    }

    if(pos == -1) cout << "UNRESTORABLE" << endl;
    else{
        for(int i=0;i<s.size();i++){
            if(i>=pos && i<pos+t.size()) s[i] = t[i-pos];
            else if(s[i]=='?') s[i] = 'a';
        }
        reverse(s.begin(),s.end());
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int old_t=0, old_x=0, old_y=0;
    bool res=true;
    for(int i=0; i<n; ++i){
        int t, x, y;
        cin >> t >> x >> y;
        if(!res) continue;
        int d=abs(x-old_x)+abs(y-old_y);
        if(d>t-old_t || d%2!=(t-old_t)%2){
            res=false;
            break;
        }
    }
    cout << (res ? "Yes" : "No") << endl;
    return 0;
}


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

long long w1,w2,hap=0,maxi,aa,bb,cc,N,i,j,k,a[100005][5];
long long M[100005][5];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(i=0; i<100003; i++)
        for(j=0; j<4; j++)
            M[i][j]=0;

    for(i=0; i<N; i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    M[N-1][0]=a[N-1][0];
    M[N-1][1]=a[N-1][1];
    M[N-1][2]=a[N-1][2];

    for(i=N-2; i>=0; i--)
    {
        for(j=0; j<3; j++)
        {
            if(j==0)
            {
                w1=1;
                w2=2;
            }
            else if(j==1)
            {
                w1=0;
                w2=2;
            }
            else
            {
                w1=0;
                w2=1;
            }
        M[i][j]=a[i][j]+max(M[i+1][w1],M[i+1][w2]);
        }
    }
    aa=max(M[0][0],M[0][1]);
    aa=max(aa,M[0][2]);
    cout<<aa<<endl;
    return 0;
}




Measured memory_bytes: 8064
# -*- coding: utf-8 -*-

N, T = map(int, input().split())

a = [list(map(int, input().split())) for i in range(N)]

# cost = 10000000

INF = 10**4
cost = INF

# print(a)

# for i, risuto in enumerate(a):
#     if risuto[1] <= T:
#         if risuto[0] <= cost:
#             cost = risuto[0]

for i, risuto in enumerate(a):
    if risuto[1] <= T and  risuto[0] <= cost:
        cost = risuto[0]



# if cost == 10000000:

if cost == INF:
    cost = 'TLE'

print(cost)






Measured memory_bytes: 3060
#
# abc059 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """36
24"""
        output = """GREATER"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """850
3777"""
        output = """LESS"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """9720246
22516266"""
        output = """LESS"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """123456789012345678901234567890
234567890123456789012345678901"""
        output = """LESS"""
        self.assertIO(input, output)


def resolve():
    A = int(input())
    B = int(input())

    if A > B:
        print("GREATER")
    elif A < B:
        print("LESS")
    else:
        print("EQUAL")


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cassert>
#include<vector>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<fstream>
#include<typeinfo>
#include<locale>
#include<iterator>
#include<valarray>
#include<complex>
#include<climits>
using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}



int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
       int s,n,k;
       cin >> n >> k >> s;
        for(int i = 1; i<=k; i++){
            cout << s << " ";
        }
        for(int i = k+1; i <=n; i++){
             if(s!=1)
            cout << s-1 << " ";
            else if(s==1) cout << s+1 <<" ";
        }


 return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
int divice(int w[],int n,int divice){
    int grupe1=0,grupe2=0;
    for(int i=0;i<=divice;i++){
        grupe1+=w[i];
    }
    for(int i=(divice+1);i<n;i++){
        grupe2+=w[i];
    }
    return abs(grupe1-grupe2);    
}
int main(){
    int n; cin>>n;
    int w[n];
    for(int i=0;i<n;i++) cin>>w[i];
    int ans[n];
    for(int i=0;i<n;i++){
        ans[i]=divice(w,n,i);
    }
    //for(int i=0;i<n;i++) cout<<ans[i]<<endl;
    int ansa=101;
    int ansi;
    for(int i=0;i<n;i++){
        if(ans[i]<ansa){
            ansa=ans[i];
            ansi=i;
        }
    }
    cout<<ansa<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
edge = {}
tree = [[] for i in range(N)]
colors = [1]*(N-1)
c_p = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    tree[a].append(b)
    edge[(a,b)] = i

for i in range(N):
    c = 1
    for v_c in tree[i]:
      while c in c_p[i]: c+=1
      colors[edge[(i,v_c)]] = c
      c_p[v_c].append(c)
      c+=1

print(max(colors))
print(*colors, sep="\n")

Measured memory_bytes: 49600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N, K;
    cin >> N >> K;
    double win = 0;
    int times;
    int ii;
    for (int i = 1; i <= N; i++)
    {
        ii = i;
        times = 0;
        while (ii < K)
        {
            times += 1;
            ii *= 2;
        }
        win += 1 / pow(2, times);
    }
    cout << setprecision(12) << win / N << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N;
  cin>>N;
  lint a[N];
  REP(i,N)cin>>a[i];
  lint S=0;
  REP(i,N)S=S^a[i];
  REP(i,N){
    cout<<(S^a[i])<<" ";
  }
  cout<<endl;
  return 0;
}


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

int main() {
  string S, x;
  int K;

  cin >> K;
  cin >> S;

  if (S.size() <= K) {
    cout << S << endl;
  } else {
    x = S.erase(K) + "...";
    cout << x << endl;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	int l,r,d;
	cin >>l >> r >> d;
	int ans = 0;
	for(int i =l;i<=r;i++){
		if(i%d==0){
			// cout << i << endl;
			ans++;
		}
	}
	cout << ans << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("faild") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();
    token.parse().ok().expect("faild")
}
fn main(){
    let a: u32 = read();
    let b: u32 = read();
    println!("{} {}",a*b,a*2+b*2);
}


Measured memory_bytes: 1052
def pf(n:int):
    r = []
    while n%2==0:
        r.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            r.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        r.append(n)
    return r

a, b = map(int, input().split())
a = pf(a)
b = pf(b)
a = set(a)
b = set(b)
print(len(set(a&b))+1)

Measured memory_bytes: 3064