akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//Nets of Dice
public class Main{

	int[][][] dice = {
			{{1,0,0,0},
			 {2,3,2,3},
			 {1,0,0,0}},
			{{1,0,0,0},
			 {2,3,2,3},
			 {0,1,0,0}},
			{{1,0,0,0},
			 {2,3,2,3},
			 {0,0,1,0}},
			{{1,0,0,0},
			 {2,3,2,3},
			 {0,0,0,1}},
			{{0,1,0,0},
			 {2,3,2,3},
			 {0,1,0,0}},
			{{0,1,0,0},
			 {2,3,2,3},
			 {0,0,1,0}},
			{{1,2,1,0,0},
			 {0,0,3,2,3}},
			{{1,2,0,0},
			 {0,3,1,3},
			 {0,2,0,0}},
			{{1,2,0,0},
			 {0,3,1,3},
			 {0,0,2,0}},
			{{1,2,0,0},
			 {0,3,1,3},
			 {0,0,0,2}},
			{{1,2,0,0},
			 {0,3,1,0},
			 {0,0,2,3}}
	};
	
	int[][] rot(int[][] a){
		int h = a.length, w = a[0].length;
		int[][] res = new int[w][h];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)res[j][i]=a[i][w-j-1];
		return res;
	}
	int[][] mirror(int[][] a){
		int h = a.length, w = a[0].length;
		int[][] res = new int[h][w];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)res[i][j]=a[i][w-j-1];
		return res;
	}
	
	void run(){
		List<int[][]> l = new ArrayList<int[][]>();
		for(int k=0;k<4;k++)for(int i=0;i<11;i++){
			l.add(dice[i]);
			l.add(mirror(dice[i]));
			dice[i] = rot(dice[i]);
		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n--!=0){
			int[][] a = new int[5][5];
			int c = 0, sum = 0;
			for(int i=0;i<5;i++)for(int j=0;j<5;j++){
				a[i][j]=sc.nextInt();
				if(a[i][j]!=0){
					c++; sum+=1<<(a[i][j]-1);
				}
			}
			if(c!=6||sum!=63){
				System.out.println(false); continue;
			}
			boolean res = false;
			int[] add = new int[4];
			for(int[][] b:l){
				int h = b.length, w = b[0].length;
				for(int i=0;i+h<=5;i++)for(int j=0;j+w<=5;j++){
					Arrays.fill(add, 0);
					boolean match = true;
					for(int y=0;y<h;y++)for(int x=0;x<w;x++){
						if(b[y][x]==0&&a[i+y][j+x]!=0 || b[y][x]!=0&&a[i+y][j+x]==0)match=false;
						add[b[y][x]]+=a[i+y][j+x];
					}
					if(match&&add[1]==7&&add[2]==7&&add[3]==7)res = true;
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import sys
N,M=map(int,input().split())
edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    edge.append([a-1,b-1,-c])
inf=10**30
dist=[inf]*N
dist[0]=0
for i in range(N):
    for x,y,z in edge:
        if dist[y]<= dist[x]+z:
            continue
        dist[y]=dist[x]+z
ans = dist[N-1]
visit=[False]*N
for i in range(N):
    for x,y,z in edge:
        if visit[x]:
            visit[y]=True
        if dist[y]<= dist[x]+z:
            continue
        visit[y]=True
        dist[y]=dist[x]+z
        
if visit[N-1]:
    print('inf')
else:
    print(-ans)

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

int main() {
	string s;
	cin >> s;
	
	if(s[s.size() - 1] == 's'){
		cout << s << "es" << endl;
	}else cout << s << 's' << endl;
	
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1000000007;
const int N = 101;
string n;
ll sumOfdigit(string n){
    ll sum = 0;
    for(int i = 0 ; i<n.size() ; i++){
        sum+= (n[i] - '0');
    }
    return sum;
}

int main(){
    fastIO;
    cin>>n;
    if(sumOfdigit(n)%9==0){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
}


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

fn main(){
    let _ = read::<i32>();
    let v = read_vec::<String>();
    for i in v{
        if i=="Y"{
            return println!("Four")
        }
    }
    println!("Three")
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn read_vec<T: FromStr>() -> Vec<T>{
    let mut buf = String::new();
    stdin().read_line(&mut buf);
    let vec : Vec<&str> = buf.split_whitespace().collect();
    let mut v : Vec<T> = vec!();
    for i in 0..vec.len(){
        v.push(vec[i].parse().ok().expect("Error"));
    }
    v
}

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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, m; cin  >> n >> m;
    vi l(m), r(m);
    rep(i,m){
        cin >> l[i] >> r[i];
    }
    int mini = *max_element(all(l));
    int maxi = *min_element(all(r));
    int answer =  maxi - mini +1;
    cout << (answer>=0 ? answer : 0) << '\n';
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

ll dp[100005][13];
ll md[100005];
ll fm = 1000000007;

void mdfun()
{
	ll i;
	ll tmp = 1;
	fr(i,0,100005)
	{
		md[i] = tmp%13;
		tmp = (tmp*10)%13;
	}	
}

int main()
{
	FAST;
	string s;
	cin >> s;
	mdfun();
	ll l = s.length(), i, j, k;
	dp[l][0] = 1;
	for(i = l-1; i >= 0; i--)
	{
		ll dg = l-1-i;
		ll m = md[dg];
		if(s[i] == '?')
		{
			fr(j,0,10)
			{
				ll tmp = (j * m)%13;
//				trace1(tmp);
				fr(k,0,13)
					dp[i][(k + tmp)%13] = (dp[i][(k + tmp)%13] + dp[i+1][k])%fm;
//				fr(k,0,13)
//					trace3(i,k,dp[i][k]);
			}
		}
		else
		{
			ll n = s[i] - '0';
			ll tmp = (n * m)%13;
			fr(k,0,13)
				dp[i][(k + tmp)%13] = (dp[i][(k + tmp)%13] + dp[i+1][k])%fm;
		}
//		fr(k,0,13)
//			trace3(i,k,dp[i][k]);
	}
	cout << dp[0][5];
}


Measured memory_bytes: 11472
def main():
    sx,sy,tx,ty=map(int, input().split())
    dx = tx-sx
    dy = ty-sy
    move = ""
    move+="U"*dy
    move+="R"*dx
    move+="D"*dy
    move+="L"*dx
    move+="D"
    move+="R"*(dx+1)
    move+="U"*(dy+1)
    move+="L"
    move+="U"
    move+="L"*(dx+1)
    move+="D"*(dy+1)
    move+="R"


    print(move)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   int a[105],n,i,mi,ma,f[15]={0};
   cin>>n;
   for(i=1;i<=n;i++)
    cin>>a[i];
   for(i=1;i<=n;i++)
   {
       if(a[i]<400&&a[i]>=1)
        f[1]+=1;
       else if (a[i]<800&&a[i]>=400)
        f[2]+=1;
        else if (a[i]<1200&&a[i]>=800)
        f[3]+=1;
        else if (a[i]<1600&&a[i]>=1200)
        f[4]+=1;
        else if (a[i]<2000&&a[i]>=1600)
        f[5]+=1;
        else if (a[i]<2400&&a[i]>=2000)
        f[6]+=1;
        else if (a[i]<2800&&a[i]>=2400)
        f[7]+=1;
        else if (a[i]<3200&&a[i]>=2800)
        f[8]+=1;
        else
        f[9]+=1;
   }
    mi=ma=0;
    for(i=1;i<=8;i++)
    {
        if(f[i]>0)
          mi+=1;
    }
    
     ma=mi+f[9];
    if(mi==0)
        mi=1;
     cout<<mi<<' '<<ma;
        return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> d(N);
    for (ll i = 0; i < N; i++) {
        cin >> d[i];
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int v[n];
    int b[n + 1];
    b[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        b[i + 1] = b[i] + v[i];
    }
    int ans = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = max(i - n, 0); j <= i / 2; j++) {
            for (int l = 0; l <= i - j; l++) {
                priority_queue<int> pque;
                int tmp = b[l] - b[0] + b[n] - b[n - i + j + l];
                for (int m = 0; m < l; m++) {
                    pque.push(-v[m]);
                }
                for (int m = n - 1; m >= n - i + j + l; m--) {
                    pque.push(-v[m]);
                }
                for (int m = 0; m < j && pque.top() > 0; m++) {
                    tmp += pque.top();
                    pque.pop();
                }
                //cout << i << ' ' << j << ' ' << l << ' ' << tmp << endl;
                ans = max(tmp, ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import exit
# A,B,C = [int(n) for n in input().split()]
Sa = list(input())
Sb = list(input())
Sc = list(input())
turn = "A"
while(True):
    if turn == "A":
        if(Sa != []):
            turn = Sa[0].upper()
            del Sa[0]
        else:
            print("A")
            exit()
    elif turn == "B":
        if(Sb != []):
            turn = Sb[0].upper()
            del Sb[0]
        else:
            print("B")
            exit()
    else:
        if(Sc != []):
            turn = Sc[0].upper()
            del Sc[0]
        else:
            print("C")
            exit()

# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
exit()


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) {
    cin >> x.at(i);
  }

  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  vector<int> d(m - 1);
  for (int i = 0; i < m - 1; i++) {
    d.at(i) = abs(x.at(i) - x.at(i + 1));
  }
  sort(d.rbegin(), d.rend());
  int d_sum = accumulate(d.begin(), d.end(), 0);
  if (n == 1) {
    cout << d_sum << endl;
    return 0;
  } else if (n == 2) {
    d_sum -= d.at(0);
  } else {
    for (int i = 0; i < n - 1; i++) {
      d_sum -= d.at(i);
    }
  }

  cout << d_sum  << endl;

}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    a=list(map(int,input().split()))
    l=[0]*N
    l2=[]
    ans=0
    for i,x in enumerate(reversed(a)):
        z=N-i
        c=0
        for j in range(2,N//z+1):
            c+=l[z*j-1]
        if c%2!=x:
            l[N-1-i]+=1
            ans+=1
            l2.append(N-i)
    print(ans)
    print(*l2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72156
#include <bits/stdc++.h>
#define mod 998244353
#define int long long
using namespace std;
const int N=310;
int n,K,dp[N][N][N],last,cnt;
int a[N],w,sum[N];
char s[N];
inline int min(int a,int b){return((a<b)?a:b);}
inline int max(int a,int b){return((a>b)?a:b);}
signed main()
{
	scanf("%s%lld",s+1,&K);
	n=strlen(s+1);
	for (int i=1;i<=n;i++) cnt+=(s[i]=='1');
	K=min(K,cnt);
	for (int i=1;i<=n;)
	{
		int j=i;
		if (s[i]=='0')
		{
			a[++w]=last;j++;last=-1;
			while (j<=n && s[i]==s[j]) w++,j++;
			i=j;
			continue;
		}
		while (j<=n && s[i]==s[j]) j++;
		last=j-i;
		i=j;
	}
	if (last!=-1) a[++w]=last;
	for (int i=1;i<=w;i++) sum[i]=sum[i-1]+a[i];
	dp[0][0][0]=1;
	for (int i=0;i<n;i++)
	{
		for (int j=sum[i];j<=cnt;j++)
		{
			for (int k=0;k<=K;k++)
			{
				if (!dp[i][j][k]) continue;
				for (int p=max(0,sum[i+1]-j);p<=cnt-j;p++)
				{
					int num=(a[i+1]>=p)?0:p-a[i+1];
					if (k+num>K) break;
					if (i+1==n && p>a[i+1]) break;
					dp[i+1][j+p][k+num]=(dp[i+1][j+p][k+num]+dp[i][j][k])%mod;
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<=K;i++) ans=(ans+dp[n][cnt][i])%mod;
	printf("%lld\n",ans);
}

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

using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;



long long fe[32];
long long k; 
void decToBinary(long long n) 
{ 
    
    memset(fe,-1,sizeof(fe));
    long long i = 0; 
    while (n > 0) { 
  
        fe[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
} 

/*int main()
{
    long long n,q,m,b1,ans=0,a1,s,cntn=0,cntp=0,cntz=0,max1=-1,max2=-1;
    cin>>n;
    vector< pair <int,int> >a;
    long long p[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>p[i];
    }
}*/

int main()
{
    long long n,a,b,c,k,y;
    cin>>n;
    if(n<9 && n>0)
        cout<<n;    
    else if( n<100)
        cout<<9;
    else if(n<1000 )
        cout<<n-99+9;
    else if(n<10000)
        cout<<909;
    else if(n<100000)
        cout<<909+n-9999;
    else if(n==100000)
        cout<<90909;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string s;
    cin >> s;
    int n = s.size();
    // dp[i][j] := マスj から 1<<i 回移動したときのマス
    vector<vector<int>> dp(20, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'L')
            dp[0][i] = i - 1;
        else
            dp[0][i] = i + 1;
    }
    for (int i = 1; i < 20; i++)
    {
        for (int j = 0; j < n; j++)
        {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }
    vector<int> ret(n, 0);
    for (int i = 0; i < n; i++)
        ret[dp[19][i]]++;
    printv(ret);
}


Measured memory_bytes: 8776
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define All(v) v.begin(),v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9+7;

signed main() {
    FAST;

    int n, a, c = 0;
    cin >> n;
    Fr(i, 0, n) {
        cin >> a;
        c += (~i&1) and (a&1);
    }
    cout << c << endl;

}


Measured memory_bytes: 3540
#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 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
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
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 out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi v;
vvi dp,sum;
ll dfs(int i,int j){
    if(i==j-1)return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    dp[i][j]=inf;
    REP(k,i+1,j)chmin(dp[i][j],dfs(i,k)+dfs(k,j)+sum[i][j]);
    return dp[i][j];
}
int main(){
    ll n;cin>>n;
    v=vi(n);
    rep(i,n)cin>>v[i];
    dp=vvi(n+1,vi(n+1,-1));
    sum=vvi(n+1,vi(n+1));
    rep(i,n+1)rep(j,n+1){
        REP(k,i,j)sum[i][j]+=v[k];
    }
    out(dfs(0,n));
}

Measured memory_bytes: 2816
#many medians
n=int(input())
B=list(map(int,input().split()))
C=B.copy()
B=sorted(B)
median1=B[n//2]
median2=B[n//2-1]
if median1==median2:
    for _ in range(n):
        print(median1)
elif median1>median2:
    for i in range(n):
        if C[i]>=median1:
            print(median2)
        else:
            print(median1)

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

int main(){
    

    int n;
    cin>>n;
    int ans=0;
    int init=-1;
    while(n--){
        int x;
        cin>>x;
        if(x>=init){
            init=x;
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
from copy import copy


def bubble_sort(C, N):
    for i in range(N):
        for j in reversed(range(i + 1, N)):
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j - 1], C[j] = C[j], C[j - 1]
    return C


def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C


def to_dict(C):
    dictionary = {n: [] for n in range(1, 36+1)}
    for card in C:
        m, i = tuple(card)
        dictionary[int(i)].append(m)
    return dictionary


N = int(input())
* C, = input().split()
C_dict = to_dict(C)
BC = bubble_sort(copy(C), N)
BC_dict = to_dict(BC)
SC = selection_sort(copy(C), N)
SC_dict = to_dict(SC)

print(*BC)
if C_dict == BC_dict:
    print('Stable')
else:
    print('Not Stable')
print(*SC)
if C_dict == SC_dict:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 6348
alp = 'abcdefghijklmnopqrstuvwxyz'
N = int(input())
ans = []

while N > 26:
    if N%26 != 0:
        ans.append(alp[N%26-1])
        N = N // 26
    else:
        ans.append(alp[N%26-1])
        N = N // 26 -1
ans.append(alp[N-1])

for i in reversed(ans):
    print(i, end="")

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n, k;
    cin >> n >> k;
    int d[k];
    for (int i = 0; i < k; i++) cin >> d[i];
    for (int i = n; i < 100000; i++) {
        string s = to_string(i);
        int m = s.size();
        bool flag = true;
        for (int j = 0; j < m; j++) {
            int t = s[j] - '0';
            if (t == *lower_bound(d, d+k, t)) flag = false;
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
}

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

using namespace std;
int main()
{
	string al[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
	string s;
	cin >> s;
	int x = 27;
	for (int i = 0; i < 26; i++) {
		if (regex_search(s, regex(al[i]))  ==false) {
			if (x > i) x = i;
		}
	}
	if (x != 27) cout << al[x] << endl;
	else cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cctype>

int main () {
    char c;
    int ans[150];
    for (int i=0; i< 150; i++) ans[i] = 0;
    while (scanf("%c", &c) != EOF) {
        char lower = tolower(c);
        ans[lower] += 1;
    }
    for (int i=97; i<123; i++) {
        printf("%c : %d\n", i, ans[i]);
    }

    return 0;
}

Measured memory_bytes: 972
N, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
X, Y = zip(*XY)
r = 10**20
for x0 in range(N - K + 1):
  for x1 in range(K + x0 - 1, N):
    Ys = sorted(Y[x0:x1 + 1])
    for y0 in range(len(Ys) - K + 1):
      r = min(r, (X[x1] - X[x0]) * (Ys[y0 + K - 1] - Ys[y0]))
print(r)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int length = arr.length;
		int[] counts = new int[length];
		for (int i = 0; i < length; i++) {
		    if (arr[i] == 'L') {
		        for (int j = i - 1; j >= 0 && arr[j] == 'R'; j--) {
		            if ((i - j) % 2 == 0) {
		                counts[i]++;
		            } else {
		                counts[i - 1]++;
		            }
		        }
		    }
		    if (arr[length - i - 1] == 'R') {
		        for (int j = length - i; j < length && arr[j] == 'L'; j++) {
		            if ((j - (length - i - 1)) % 2 == 0) {
		                counts[length - i - 1]++;
		            } else {
		                counts[length - i]++;
		            }
		        }
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
		    if (i != 0) {
		        sb.append(" ");
		    }
		    sb.append(counts[i]);
		}
		System.out.println(sb);
   }
}


Measured memory_bytes: 28376
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static int evaluate(String[] strArray) {
		int answer = 0;
		String operators = "+-*";
 
		Stack<String> stack = new Stack<String>();
 
		for (int i = 0; i < strArray.length; i++) {
			String elem = strArray[i];
			if (!operators.contains(elem)) {
				stack.push(elem);
			} else {
				int a = Integer.valueOf(stack.pop());
				int b = Integer.valueOf(stack.pop());
				switch (elem) {
				case "+":
					stack.push(String.valueOf(a + b));
					break;
				case "-":
					stack.push(String.valueOf(b - a));
					break;
				case "*":
					stack.push(String.valueOf(a * b));
					break;
				case "/":
					stack.push(String.valueOf(b / a));
					break;
				}
			}
		}
		
		answer = Integer.valueOf(stack.pop());
 
		return answer;
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String input = scan.nextLine();
		scan.close();
		String[] strList = input.split(" ");
		
		
		
		System.out.println(evaluate(strList));
		
		
	}
}


Measured memory_bytes: 26152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;
  int c[SIZE];
  ll dp[SIZE] = {};

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%d", c+i);
  }

  ll cur = 1;

  for(int i=0;i<n;i++){
    if(i > 0 && c[i-1] != c[i])
      cur = (cur + dp[c[i]]) % mod;
    dp[c[i]] = cur;
  }

  cout << cur << endl;

  return 0;
}


Measured memory_bytes: 2688
all_number = gets.to_i
input_judge = gets.chomp!
judge = input_judge.split('')
judges = []

for i in 0..all_number do
    judges << judge[i]
end

red = judges.count("R")
blue = judges.count("B")

if red > blue
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        int ans  = 0;
        for (int i = 0; i < N; i++) {
            Set<Character> set = new HashSet<>();
            set.add(A.charAt(i));
            set.add(B.charAt(i));
            set.add(C.charAt(i));
            if (set.size() == 3) {
                ans += 2;
            } else if (set.size() == 2) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22740
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

while True:
    for i in range(n):
        if i == 0:
            continue
        else:
            a[i] %= a[0]
    a.sort()
    t = 0
    for t in range(n):
        if a[t]!=0:
            break
    a = a[t:]
    n = len(a)
    if n==1:
        break;
print(a[n-1])


Measured memory_bytes: 14224
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	int ta,tb,tc;
	while(a%2==0&&b%2==0&&c%2==0&&ans>=0){
			ta=b/2+c/2;
			tb=a/2+c/2;
			tc=a/2+b/2;
			a=ta,b=tb,c=tc;
			ans+=1;
		//	if(a==b&&b==c)ans=-1;
			if(ans>1e6)ans=-1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import Counter

input()
a_list = list(map(int, input().split()))

c = Counter(a_list)
divisible = [True] * (10**6+1)
for el, count in c.items():
    if count!=1:
        divisible[el] = False
    for i in range(el*2, 10**6+1, el):
        divisible[i] = False
a_list = list(set(a_list))
ans = len(
    [1 for a in a_list if divisible[a]]
)    
print(ans)

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

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var A = GetIntArray();
            var max = int.MinValue;
            var min = int.MaxValue;
            for(int i = 0; i < N; i++)
            {
                max = Math.Max(max, A[i]);
                min = Math.Min(min, A[i]);
            }

            var ans = Math.Abs(max - min);
            Console.Write(ans);
        }



        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll n; cin >> n;
  ll A = 26;
  vector<ll> cnt(A, 50);
  REP(i, n){
    string s; cin >> s;
    vector<ll> tmp(A, 0);
    REP(j, s.size()){
      tmp[s[j]-'a']++;
    }
    REP(j, A){
      cnt[j] = min(cnt[j], tmp[j]);
    }
  }

  string ans = "";
  REP(i, A){
    char ch = 'a' + i;
    REP(j, cnt[i]){
      ans = ans + ch;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int blue[2001][2001];
int cc[2001][2001];
int rc[2001][2001];
bool tab[2001][2001];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,q;
	char ch;
	cin>>n>>m>>q;
	rep(i,n){
		rep(j,m){
			cin>>ch;
			tab[i+1][j+1]=(ch=='1');
		}
	}
	range(i,1,n+1){
		range(j,1,m+1){
			blue[i][j]=blue[i][j-1]+(blue[i-1][j]-blue[i-1][j-1]);
			blue[i][j]+=tab[i][j];
			rc[i][j]=rc[i][j-1];
			cc[i][j]=cc[i][j-1];
			if(tab[i][j]){
				rc[i][j]+=tab[i-1][j];
				cc[i][j]+=tab[i][j-1];
			}
		}
	}
	range(i,1,n+1){
		range(j,1,m+1){
			rc[i][j]+=rc[i-1][j];
			cc[i][j]+=cc[i-1][j];
		}
	}
	int a,b,c,d;
	while(q--){
		cin>>a>>b>>c>>d;
		int node=blue[c][d]+blue[a-1][b-1]-blue[c][b-1]-blue[a-1][d];
		int edge=0;
		edge+=rc[c][d]+rc[a][b-1]-rc[c][b-1]-rc[a][d];
		edge+=cc[c][d]+cc[a-1][b]-cc[c][b]-cc[a-1][d];
		cout<<node-edge<<"\n";
	}
}


Measured memory_bytes: 52608
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <functional>
#define REP(i, n) for(int i = 0; i < n; i++)
//using ll = long long;
using namespace std;
const int mod = 1000000007;

int main() {
 

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

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  while(a >= 0 && c >= 0){
    c = c-b;
    if (c <= 0){
      cout << "Yes" << endl;
      break;
    }
    a = a-d;
    if (a <= 0){
      cout << "No" << endl;
      break;
    }
  }
  
 
  
  
      
}


Measured memory_bytes: 3640
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto ss = reads!string;
    auto a = ss[0], b = ss[1], c = ss[2];

    if (a[$-1] == b[0] && b[$-1] == c[0])
        writeln("YES");
    else
        writeln("NO");
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

struct NODE{
	int from,to,cost;
	NODE(int from,int to,int cost) : from(from),to(to),cost(cost){}
};
bool operator <(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}

vector<NODE> e[3000];
vector<NODE> edge;
int cost[3000];
int main(){
	int N,M,K;
	scanf("%d%d%d",&N,&M,&K);
	memset(cost,-1,sizeof(cost));
	for(int i = 0 ; i < M ; i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		--a,--b;
		e[a].push_back(NODE(a,b,c));
		e[b].push_back(NODE(b,a,c));
		edge.push_back(NODE(a,b,c));
	}
	priority_queue<NODE> Q;
	for(int i = 0 ; i < K ; i++){
		int a; scanf("%d",&a);
		Q.push(NODE(-1,a-1,0));
	}
	
	while(Q.size()){
		NODE q = Q.top(); Q.pop();
		if(cost[q.to] != -1) continue;
		else cost[q.to] = q.cost;
		for(int i = 0 ; i < e[q.to].size() ; ++i) Q.push(NODE(-1,e[q.to][i].to,q.cost+e[q.to][i].cost));
	}
	int answer = 0;
	for(int i = 0 ; i < M ; i++){
		answer = max( answer , (cost[edge[i].from] + cost[edge[i].to] + edge[i].cost + 1 ) / 2 );
	}
	printf("%d\n",answer);
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int myexp(int b, int p)
{
    int ans = 1;
    REP(i, p) ans*= b;
    return ans;
}


int main(void)
{
    int x;
    int ma = 1;
    cin >> x;
    int expij;
    for(int i = 2; i <= x; i++) {
        for(int j = 2; (expij = myexp(i, j)) <= x; j++) {
            ma = max(ma, expij);
        }
    }
    cout << ma << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m;
    if(n==m)
    {
        cout<<"Draw\n";
    }
    else if(n==1)
    {
        cout<<"Alice\n";
    }
    else if(m==1)
    {
        cout<<"Bob\n";
    }
    else
    {
        (n>m)? cout<<"Alice\n": cout<<"Bob\n";
    }
    return 0;
}



Measured memory_bytes: 256
n,m,x = map(int,input().split())
t = []
for i in range(n):
  ti = list(map(int,input().split()))
  t.append(ti)
mn = float("inf")
flag = False
for i in range(2**n):
  cost = 0
  a =[0]*m
  j = 0
  while i > 0:
    if i%2 == 1:
      cost += t[j][0]
      for k in range(m):
        a[k] += t[j][1+k]
    i = i//2
    j += 1
  if min(a)>=x:
    flag = True
    if cost < mn:
      mn = cost
if flag:
  print(mn)
else:
  print(-1)
        
      
  

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

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int ans=a*x+b*y;
  
  for(int i=1;i<=max(x,y);i++){
    ans=min(ans,max(x-i,0)*a+max(y-i,0)*b+c*2*i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void pairsort(int a[], int b[], int n) 
{ 
    pair<int, int> pairt[n]; 
  
    for (int i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    } 
  
    sort(pairt, pairt + n); 
    for (int i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
} 
int main() {
	int n,w;
	cin >>n>>w;
	int wt[n],values[n];
	for(int i=0;i<n;i++)
	    cin>>wt[i]>>values[i];
	pairsort(wt,values,n);
	long long int knapsack[n+1][w+1];
	for(int i=0;i<=n;i++)
	    for(int j=0;j<=w;j++)
	        {
	            if(i==0 || j==0)
	                knapsack[i][j]=0;
	            else if(j>=wt[i-1])
	                {
	           
	                    knapsack[i][j]=max(values[i-1]+knapsack[i-1][j-wt[i-1]],knapsack[i-1][j]);
	                }
	            else
	                knapsack[i][j]=knapsack[i-1][j];
	        }
	cout<<knapsack[n][w];
}


Measured memory_bytes: 79104
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int q;
bool is_prime[100005];

void sieve(int n) {
  int p = 0;
  for(int i=0; i<=n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;

  for(int i=2; i<=n; i++) {
    if(is_prime[i]) {
      for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
    }
  }
}

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

  cin >> q;
  sieve(100000 + 1);

  vector<int> like_sum(100000 + 1, 0);
  int sum = 0;

  for(int i=1; i<=100001; i++) {
    if(i % 2 != 0) {
      if(is_prime[i] && is_prime[(i + 1) / 2]) {
        sum += 1;
      }
    }
    like_sum[i] = sum;
  }

  REP(i, q) {
    int l, r;
    cin >> l >> r;
    cout << like_sum[r] - like_sum[l - 1] << endl;
  }
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
        int n,k,p;
        int ans = 0;
        vector<int> v;

        cin >> n >> k;
        for (int i = 0; i < n; ++i){
                cin >> p;
                v.push_back(p);
        }
        sort(v.begin(), v.end());

        for (int j = 0; j < k; ++j){
                ans += v[j];
        }
        cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

template <class T>
void print(const T &value) {
    cout << value << endl;
}

bool isOdd(int x) { return x % 2 != 0; }

int main() {
    int N;
    string S;

    cin >> N >> S;

    if (isOdd(N)) {
        cout << "No" << endl;
        return 0;
    }

    rep(i, N / 2) {
        if (S[i] != S[i + N / 2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int t[n],T = 0;
  for(int i = 0;i < n;i++){
    cin >> t[i];
    T += t[i];
  }
  double v[2*T+1];
  for(int i = 0;i < 2*T+1;i++){
    v[i] = 1000000;
  }
  int tsum = 0;
  for(int i = 0;i < n;i++){
    double vc;
    cin >> vc;
    for(int j = tsum;j <= tsum + 2*t[i];j++){
      v[j] = min(v[j],vc);
    }
    tsum += 2*t[i];
  }
  v[0] = 0;
  v[2*T] = 0;
  for(int i = 1;i < 2*T+1;i++){
    v[i] = min(v[i-1]+0.5,v[i]);
  }
  for(int i = 2*T-1;i > 0;i--){
    v[i] = min(v[i+1]+0.5,v[i]);
  }
  for(int i = 0;i <= 2*T;i++){
    //cout << i/2 << ' ' <<  v[i] << endl;
  }
  double result = 0;
  for(int i = 0;i < 2*T;i++){
    result += (v[i] + v[i+1])*0.25;
  }
  printf("%.16f\n", result);
}

Measured memory_bytes: 512
MOD = 998244353
N, M, K = map(int, input().split())

factorials = [1]
fact_invs = [1]
for i in range(1, N+1):
    factorials.append((factorials[-1]*i) % MOD)
    fact_invs.append(pow(factorials[-1], MOD-2, MOD))

ans = 0
for k in range(K+1):
    tmp = factorials[N-1]
    tmp *= fact_invs[k]
    tmp %= MOD
    tmp *= fact_invs[N-1-k]
    tmp %= MOD
    tmp *= M * pow(M-1, N-1-k, MOD)
    ans += tmp
    ans %= MOD
print(ans)


Measured memory_bytes: 24832
N = int(input())

PRIMES = 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97

xs = {}

for n in range(2, N+1):
    for p in PRIMES:
        while n % p == 0:
            n //= p
            xs[p] = xs.get(p, 0) + 1
        if n == 1:
            break

vs = sorted(xs.values())

u74 = sum(v >= 74 for v in vs)
u24 = sum(v >= 24 for v in vs)
u14 = sum(v >= 14 for v in vs)
u4 = sum(v >= 4 for v in vs)
u2 = sum(v >= 2 for v in vs)

# print(u74, u24, u14, u4, u2)

def nCr(n, r):
    result = 1
    for i in range(n - r + 1, n + 1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    # print("nCr", n, r, result)
    return result

result = 0

# 75
result += u74

# 25 * 3
if u24 >= 1 and u2 - u24 >= 1:
    result += nCr(u24, 1) * nCr(u2 - 1, 1)

# 15 * 5
if u14 >= 1 and u4 - u14 >= 1:
    result += nCr(u14, 1) * nCr(u4 - 1, 1)

# 5 * 5 * 3
if u4 >= 2 and u2 - u4 >= 1:
    result += nCr(u4, 2) * nCr(u2 - 2, 1)

print(result)


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

int main(){
	int i, j, n, m, a, index;
	vector<int>::iterator vi;
	while(true){
		cin>>n>>m;
		if(n==0) break;
		vector<int> v(m, 0);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				cin>>a;
				if(a){
					v[j]++;
				}
			}
		}
		vi = max_element(v.begin(), v.end());
		index = distance(v.begin(), vi);
		*vi = -1;
		cout << index+1;
		while(true){
			vi = max_element(v.begin(), v.end());
			if(*vi==-1)break;
			index = distance(v.begin(), vi);
			*vi = -1;
			cout << " " << index+1;
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  for (auto &e : a) {
    cin >> e.first >> e.second;
  }
  sort(begin(a), end(a));
  ll r = 0;
  for (auto e : a) {
    ll x = min(m, e.second);
    r += x * e.first;
    m -= x;
    if (!m) {
      break;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit
from collections import deque
from bisect import bisect_left


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = deque()
    for ai in a:
        idx = bisect_left(ans, ai)
        if idx == 0:
            ans.appendleft(ai)
        else:
            ans[idx - 1] = ai

    print(len(ans))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 45240
N = int(input())

words = [input() for _ in range(N)]
prev = words[0]
se = set([words[0]])

bl = True
for w in words[1:]:
    if w in se:
        bl = False
    if prev[-1] != w[0]:
        bl = False
    se.add(w)
    prev = w

answer = 'Yes' if bl else 'No'
print(answer)

Measured memory_bytes: 3064