akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

signed main() {
	string S;
	cin >> S;

	int A = 0;
	int AB = 0;
	int ret = 0;
	int base = 1;

	for (char ch : S) {
		if (ch == 'A') {
			A += base;
			A %= MOD;
		} else if (ch == 'B') {
			AB += A;
			AB %= MOD;
		} else if (ch == 'C') {
			ret += AB;
			ret %= MOD;
		} else if (ch == '?') {
			ret = 3 * ret + AB;
			AB = 3 * AB + A;
			A = 3 * A + base;
			ret %= MOD;
			AB %= MOD;
			A %= MOD;

			base *= 3;
			base %= MOD;
		}
	}

	cout << ret << endl;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
a.sort()
free=0
cset=set()
for rate in a:
    color = int(rate / 400)
    if color >=8:
        free+=1
    else:
        cset.add(color)

colormin=len(cset)
colormax=colormin+free

print(str(max(1,colormin)), colormax)

Measured memory_bytes: 3060
import math
list = input().split()
x1 = float(list[0])
y1 = float(list[1])
x2 = float(list[2])
y2 = float(list[3])

print("{:.5f}".format(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)))


Measured memory_bytes: 5652
//Cut and Count

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n;cin>>n;
    string s;cin>>s;
    int ans=0;
    set<char>a,b;
    rep(i,1,n-1){
        set<char>a,b;
        a.clear();b.clear();
        rep(j,0,i){
            a.insert(s[j]);
        }
        rep(j,i,n){
            b.insert(s[j]);
        }
        int c=0;
        irep(i,b){
            if(a.find(*i)!=a.end())c++;
        }
        ans = max(ans,c);
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, w) = scan!(usize, usize);
    let vs = scan!(usize, usize; n);
    let weight = vs[0].0 as usize;

    let mut kinds: Vec<Vec<usize>> = vec![vec![]; 4];
    for v in vs {
        kinds[(v.0 - weight) % 4].push(v.1);
    }

    for k in kinds.iter_mut() {
        k.sort()
    }
    let mut sums: Vec<usize> = vec![];
    for i in 0..kinds[0].len() + 1 {
        for j in 0..kinds[1].len() + 1 {
            for k in 0..kinds[2].len() + 1 {
                for l in 0..kinds[3].len() + 1 {
                    if (i + j + k + l) * weight + j + 2 * k + 3 * l <= w {
                        sums.push(
                            kinds[0].iter().rev().take(i).sum::<usize>()
                                + kinds[1].iter().rev().take(j).sum::<usize>()
                                + kinds[2].iter().rev().take(k).sum::<usize>()
                                + kinds[3].iter().rev().take(l).sum::<usize>(),
                        )
                    }
                }
            }
        }
    }

    if let Some(v) = sums.iter().max() {
        println!("{}", v)
    } else {
        println!("0")
    }
}


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();

		int tastesum = N*(L-1) + N*(1+N)/2;

		int mintaste = Integer.MAX_VALUE;
		int mintasteabs = Integer.MAX_VALUE;
		for(int i=1;i<=N;i++) {
			int t = L+i-1;
			if(mintasteabs > Math.abs(t)) {
				mintaste = t;
				mintasteabs = Math.abs(t);
			}
		}
		System.out.println(tastesum - mintaste);
	}
}

Measured memory_bytes: 23508
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int candy[100005];
int main(){

    ios :: sync_with_stdio(false);
    int N;
    cin >> N;

    FOR(i,N) cin >> candy[i];
    sort(candy+1, candy+1+N);

    int cur = 0;
    FORD(i,N,1){
        cur++;
        if(cur >= candy[i-1]){
            if((candy[i]-cur)&1){
                cout << "First" << endl;
            }
            else{
                FORD(j,i,0){
                    if(cur >= candy[j-1]+1){
                        if((j-i)&1){
                            cout << "First" << endl;
                        }
                        else cout << "Second" << endl;
                        break;
                    }
                }
            }
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	string s,tmp;

	for(int i=0;i<2000;i++) tmp+='a';

	while(getline(cin,s)){

		int pos=0;
		while((pos=s.find("apple"))!=string::npos){
			s.replace(pos,5,tmp);
		}

		pos=0;
		while((pos=s.find("peach"))!=string::npos){
			s.replace(pos,5,"apple");
		}

		pos=0;
		while((pos=s.find(tmp))!=string::npos){
			s.replace(pos,2000,"peach");
		}

		cout<<s<<endl;

	}

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    int n, x;
    cin >> n >> x;

    int r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a -= x;
        r = gcd(r, abs(a));
    }

    cout << r << endl;

    return 0;
}

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

int main() {
  int H,W;
  cin >> H >>W;
  string S[H];
  int dx[8] = {-1,0,1,-1,1,-1,0,1};
  int dy[8] = {-1,-1,-1,0,0,1,1,1};
  for(int i=0; i<H ;i++)  cin >> S[i];
  for(int i=0; i<H ;i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '#') continue;
      
      int count=0;
      for(int d=0; d<8; d++){
        int ni = i + dx[d];
        int nj = j + dy[d];
        if (ni < 0 || ni > H) continue;
        if (ni < 0 || ni > H) continue;
        if (S[ni][nj] == '#') count++;
      }
      S[i][j] = count+'0';
    }
  }
  for(int i=0; i<H ;i++)  cout << S[i] << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=305,mo=1e9+7;
int n,m,i,j,k,mn[N][3],mx[N][3],f[N][N],ans;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void add(int &x,int k){x=(x+k)%mo;}
int main(){
	for (n=read(),m=read(),i=1;i<=n;i++)
		for (j=0;j<3;j++) mn[i][j]=n;
	for (;m--;){
		int y=read(),x=read(),k=read()-1;
		mn[x][k]=min(mn[x][k],y);
		mx[x][k]=max(mx[x][k],y);
	}
	for (f[0][0]=1,i=0;i<=n;i++)
		for (j=i;~j;j--) for (k=j;~k;k--) if (f[j][k]){
			int v=f[j][k];f[j][k]=0;
			if (mx[i][0]&&mn[i][0]<=j) continue;
			if (mx[i][1]&&(mx[i][1]>j||mn[i][1]<=k)) continue;
			if (mn[i][2]&&mx[i][2]>k) continue;
			if (i==n){add(ans,v);continue;}
			add(f[j][k],v);add(f[i][j],v);add(f[i][k],v);
		}
	printf("%d",ans);
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

    ll a,b;
    cin >> a >> b;

    if ((a+b)%2 == 0) {
      cout << (a+b) / 2 << endl;
    } else {
      cout <<"IMPOSSIBLE\n";
    }
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

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

    map<string,ll> Counter;
    for(ll i=0;i<N;i++)
    {
        string s;
        cin >> s;

        Counter[s]++;
    }

    cout << "AC x " << Counter["AC"] << endl; 
    cout << "WA x " << Counter["WA"] << endl;
    cout << "TLE x " << Counter["TLE"] << endl;
    cout << "RE x " << Counter["RE"] << endl;

    return 0;
}

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

int main() {
  int H,W; cin >>H >>W;
  vector<vector<char>> vec(H+2, vector<char>(W+2,'#'));
  rep(i,0,H) {
    string a; cin >>a;
    rep(j,0,W) {
      vec[i+1][j+1]=a[j];
    }
  }
  rep(i,0,H+2) {
    rep(j,0,W+2) cout <<vec[i][j];
    cout <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(ll i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    ll n;cin>>n;
    ll a[n+1];
    rep(i,n) cin>>a[i];
    ll ans=0,tmp2=1;
    ll xo[60];
    rep(i,60) xo[i]=0;
    rep(i,60){
        rep(j,n){
            if((a[j]>>i)&1) xo[i]++;
        }
        ans+=(((tmp2*xo[i])%MOD)*(n-xo[i]))%MOD;
        ans%=MOD;
        tmp2*=2;tmp2%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#import<bits/stdc++.h>
using namespace std;long L,R,D,M=998244353,l,r,d,z,A['   '];map<int,int>m;main(){cin>>l>>r;for(m[l]=1;l--;A[l]=++z%=M)z*=10;for(;cin>>L>>R>>D;cout<<(z%=M)<<" "){z+=D*(A[--L]-A[R])+M*M;auto t=m.lower_bound(l=L);for(d=t->second;z-=t->second*(A[l]-A[r=min(R,l=t->first)]),r<R;t=m.erase(t));m[L]=d;m[R]=D;}}

Measured memory_bytes: 14580
#include <iostream>
#include <vector>
#include <string.h>
using namespace std ;


int main(void) {
    //vector<char> S ;
    char S[10000] ;
    int N ;

    cin >> N;
    cin >> S;

    char eng[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'};
    
    int len = strlen(S) ;
    //cout << "len =" << len << endl ;

    int index = 0 ;
    for (int i = 0; i < len; i++) {
        for (int j = 0; j < 26; j++) {
            if (S[i] == eng[j])
                index = j + N ;
            index = index % 26;
        }
        cout << eng[index] ;
    }
    cout << "\n" ;

    return 0 ;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

# 1個目と2個目の約数列挙
# ⇨ 1個しか消さないから必ずどちらかの約数は残る
divs = make_divisors(As[0]) + make_divisors(As[1])
divs = list(set(divs))
cnt = 1

for div in sorted(divs,reverse=True):
    a = sum([1 for a in As if a%div == 0])
    if n - a <= 1:
        print(div)
        exit()

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


    ll n,m;
    cin >> n >> m;
    cout << n*m << '\n';

    return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    ll n;
    cin>>n;
    if(n%1000==0)
    cout<<0<<endl;
    else
    cout<<((n/1000+1)*1000)-n<<endl;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#define N 100010
#define LL long long
using namespace std;
int n, e, t;
int x[N];
LL dp[N];
multiset<LL> st1;
multiset<LL> st2;

int main() {
	scanf("%d%d%d", &n, &e, &t);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &x[i]);
	}
	
	dp[0] = 0;
	x[0] = 0;
	int last = 0;
	st1.insert(- 2LL * x[1]);
	st2.insert(t);
	for (int i = 1; i <= n; ++i) {
		while (last + 1 <= i && 2LL * (x[i] - x[last + 1]) >= t) {
			st1.insert(dp[last] - x[last] - 2LL * x[last + 1]);
			st2.erase(st2.find(dp[last] - x[last] + t));
			++last;
		}
		if (last - 1 >= 0) dp[i] = min(*st1.begin() + 3LL * x[i], *st2.begin() + x[i]);
		else dp[i] = *st2.begin() + x[i];
		st2.insert(dp[i] - x[i] + t);
//cout << dp[i] << ' ';
	}
//cout << endl;
	
	cout << dp[n] + e - x[n];
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N, K, M;
  cin >> N >> K;
  M = 2*K;
  vector<vector<int>> b(M+1,vector<int>(M+1,0));
  rep(i,N) {
    int x,y;
    string c;
    cin >> x >> y >> c;
    x %= M; y %= M;
    if (c == "W") {
      x += K;
      x %= M;
    }
    b[x+1][y+1]++;
  }
  rep1(i,M) {
    rep1(j,M) {
      b[i][j] += b[i][j-1];
    }
  }
  rep1(i,M) {
    rep1(j,M) {
      b[i][j] += b[i-1][j];
    }
  }
  int ans = 0;
  rep(i,K) {
    rep(j,K) {
      int tmp;
      tmp = b[i+K][M]+b[M][j+K]-b[i][M]-b[M][j]-2*b[i+K][j+K]+2*b[i][j+K]+2*b[i+K][j]-2*b[i][j];
      ans = max(ans,tmp);
      tmp = b[M][M]-tmp;
      ans = max(ans,tmp);
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 19104
import queue
N,K=map(int,input().split())
P=list(map(int,input().split()))
que=queue.Queue()
que_tmp=queue.Queue()
ans=0
tmp=0
cnt=0
for p in P:
    if cnt<K:
        que_tmp.put(1+p)
        tmp+=1+p
        cnt+=1
    else:
        que.put(1+p)

while not que.empty():
    dis=que_tmp.get()
    plus=que.get()
    que_tmp.put(plus)
    tmp+=plus-dis
    ans=max(ans,tmp)
print(max(ans,tmp)/2)

Measured memory_bytes: 78280
# include <iostream>
# include <vector>
# include <string>


using namespace std;


const int N = 13;
const int MOD = 1e9+7;
const int REM = 5;


int main() {
    string s; cin >> s;
    int n_digits = s.size();

    vector<vector<long>> dp(n_digits+1, vector<long>(13, 0));
    dp[0][0] = 1;

    int c;
    for (int i=0; i<n_digits; i++) {
        c = (s[i] == '?') ? -1 : s[i]-'0';

        if (c == -1) {
            for (int j=0; j<10; j++) {
                for (int k=0; k<13; k++) {
                    dp[i+1][(k*10+j)%N] += dp[i][k];
                }
            }
        }

        else {
            for (int k=0; k<13; k++) {
                dp[i+1][(k*10+c)%N] += dp[i][k];
            }
        }

        for (int k=0; k<13; k++) {
            dp[i+1][k] %= MOD;
        }
    }

    cout << dp[n_digits][REM] << endl;
}


Measured memory_bytes: 13632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];

  ll ans = 0;
  rep(i,n-1) ans += min((x[i+1]-x[i])*a,b);
  cout << ans << endl;
}

Measured memory_bytes: 3952
#include <stdio.h>

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

#define INF 1000000000

int main(void) {
	int i, j, o;
	int n, m, l, k, a, h;

	while (scanf("%d %d %d %d %d %d", &n, &m, &l, &k, &a, &h), n) {
		int canFreeze[100] = {0}, adj[100][100];

		canFreeze[a] = canFreeze[h] = 1;
		for (i = 0; i < l; i++) {
			int x;
			scanf("%d", &x);
			canFreeze[x] = 1;
		}

		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				adj[i][j] = INF;
		for (i = 0; i < k; i++) {
			int x, y, t;
			scanf("%d %d %d", &x, &y, &t);
			adj[x][y] = adj[y][x] = t;
		}

		for (o = 0; o < n; o++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					adj[i][j] = min(adj[i][j], adj[i][o] + adj[o][j]);

		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (!canFreeze[i] || !canFreeze[j] || adj[i][j] > m)
					adj[i][j] = INF;

		for (o = 0; o < n; o++)
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					adj[i][j] = min(adj[i][j], adj[i][o] + adj[o][j]);

		if (adj[a][h] != INF)
			printf("%d\n", adj[a][h] + max(0, adj[a][h] - m));
		else
			puts("Help!");
	}

	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	int a=0,b=0;
	char c,h;
	cin>>s;
	for(int i=0;i<s.size();i++){
		c=s[0];
		if(s[i]!=c){
			h=s[i];
		}
	}
	for(int i=0;i<s.size();i++){
		if(s[i]==c){
			a++;
		}
		else if(s[i]==h){
			b++;
		}
	}
	if(a==b&&a==2){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
	
}
 

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

int main()
{
    vector<vector<char>> c(3, vector<char>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c.at(i).at(j);
        }
    }
    for (int i = 0; i < 3; i++)
    {
        cout << c.at(i).at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::HashMap;
use std::io;

fn read_line() -> String {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line).unwrap();
    return String::from(line.trim());
}

fn main() {
    let nk: Vec<String> = read_line().split_whitespace().map(|s| String::from(s)).collect();
    let n: i64 = nk.get(0).unwrap().parse::<i64>().unwrap();
    let k: i64 = nk.get(1).unwrap().parse::<i64>().unwrap();
    let values: Vec<String> = read_line().split_whitespace().map(|s| String::from(s)).collect();

    let mut counts: HashMap<String, i64> = HashMap::new();
    for value in values {
        *counts.entry(value).or_insert(0) += 1;
    }
    let mut values: Vec<i64> = counts.values().into_iter().map(|i| *i).collect();
    values.sort();
    values.reverse();
    let sum = values[..cmp::min(values.len(), k as usize)].iter().sum::<i64>();
    println!("{}", values.iter().sum::<i64>() - sum);
}

Measured memory_bytes: 27344
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=100+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;string s[N];
int main(){
	n=read();
	rep(i,1,n)cin>>s[i];
	rep(i,1,n-1)rep(j,i+1,n)
	if(s[i]==s[j]){puts("No");return 0;}
	rep(i,1,n-1)
	if(s[i][s[i].length()-1]!=s[i+1][0]){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
def main():
    n= int(input())
    s= input()

    r = s.count("R")
    g = s.count("G")
    b = s.count("B")

    ans = r * g * b
    snum = tuple(s[:])
    for i in range(1,n-1):
        for j in range(i,n):
            k = j * 2 - i
            if k > n:
                break

            if snum[i-1] != snum[j-1] and snum[i-1] != snum[k-1] and snum[j-1] != snum[k-1]:
                ans -= 1

    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s,t,u;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  cin>>u;
  if(s==u)
  {
    cout<<a-1<<" "<<b;
  }
  else
    cout<<a<<" "<<b-1;
}

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

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

    long long n, a, b;
    cin >> n >> a >> b;
    vector<long long> X(n);
    for(int i = 0; i < n; i++){
        cin >> X[i];
    }

    long long ans = 0;
    for(int i = 1; i < n; i++){
        ans += min((X[i] - X[i - 1]) * a, b);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int s[n];
    for(int i=0;i<4;i++){
        s[3-i]=n%10;
        n/=10;
    }
    for(int i=0;i<(1<<3);i++){
        int p=s[0];
        char t[3];
        for(int j=0;j<3;j++){
            if(i&(1<<j)){
                p-=s[j+1];
                t[j]='-';
                }
            else{
                p+=s[j+1];
                t[j]='+';
            }
        }
        if(p==7){
            cout<<s[0]<<t[0]<<s[1]<<t[1]<<s[2]<<t[2]<<s[3]<<"=7"<<endl;
            return 0;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int &e : h) cin >> e;
  
  int tesu = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) tesu += h[0];
    else if (h[i-1] < h[i]) tesu += h[i]-h[i-1];
  }
  cout << tesu << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    //初期条件、初期化は既に終わっている

    //遷移
    for (ll i = 0;i<N;i++) {
        for (ll j = 0;j<3;j++) {
            for (ll k = 0;k<3;k++) {
                if (j==k) continue;
                chmax(dp[i+1][k],dp[i][j] + a[i][k]);
            }
        }
    }
    ll ans = max(dp[N][0],dp[N][1]); //dp[i] はi日目なので注意,
    ans = max(ans,dp[N][2]);         //N日目はN-1でなく、dp[N]なので注意
    cout << ans << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;
import static java.lang.System.out;
public class Main{
  static Scanner sc=new Scanner(System.in);

   public static void main(String[] args){
      String c1 = sc.next();
      String c2 = sc.next();
      String c3 ="";
      for(int i =3;i>0;i--){
         c3 += c1.substring(i-1,i);
      }
      

      if(c3.equals(c2)){
         out.println("YES");
      }else{
         out.println("NO");
      }
    
    
  } 
}

Measured memory_bytes: 21972
# coding:utf-8

import sys
from collections import deque, defaultdict

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

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


def main():
    n, m = LI()
    AB = [LI() for _ in range(n)]
    AB.sort()
    AB = deque(AB)

    cnt = 0
    res = 0
    while cnt < m:
        a, b = AB.popleft()
        cnt += b
        res += a * b

    if cnt > m:
        res -= a * (cnt - m)

    return res


print(main())


Measured memory_bytes: 22280
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/

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

#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)

//bottom up 型　DP

LL min(LL a, LL b){
  if(a>b)return b;
  else return a;
}

int main(void)
{
  LL N;
  LL q = 0;
  LL ans = 0;
  LL H[100000];
  LL DP[100000]={0};

  scanf("%lld", &N);
  for (LL i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }

  DP[0] = 0;
  DP[1] = ABS(H[1] - H[0]);

  for (size_t i = 2; i < N; i++) {
    DP[i] = min(DP[i-1]+ABS(H[i-1]-H[i]) , DP[i-2]+ABS(H[i-2]-H[i]));
  }
  ans = DP[N-1];
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h> 
using namespace std; 
  
// Return the maximum volume. 
double maxvolume(double s) 
{ 
    // finding length 
    double length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    double breadth = s / 2; 
  
    // finding height 
    double height = s - breadth; 
  
    return length * breadth * height; 
} 
  
// Driven Program 
int main() 
{ 
    double s = 8; 
    cin>>s;
    cout<<fixed << setprecision(12) << maxvolume(s) << endl; 
    return 0; 
} 

Measured memory_bytes: 256
input = readlines
a, b = input[0].chomp, input[1].chomp
#puts a.match?(Regexp.new(b.gsub(/_/, '[A-Z]'))) ? 'Yes' : 'No'
#--------
a_len = a.length
b_len = b.length
match = false
(a_len - b_len + 1).times do |i|
  substr = a[i, b_len]
  match_count = substr.chars.each_with_index.inject(0) do |sum, (ac, i)|
    break sum unless b[i] == '_' || ac == b[i]
    sum += 1
  end
  if match_count == b_len
    match = true
    break
  end
end
puts match ? 'Yes' : 'No'


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

using namespace std;
#define N 200100
#define SIGMA 26
int i, n;
int v[N];
int main()
{
    int T = 1;
    //cin >> T;
    for (int tt = 0; tt < T; ++tt){
        cin >> n;
        for (i = 0; i < n; ++i)
            cin >> v[i];
        sort (v, v + n);
        for (i = 1; i < n; ++i)
        if (v[i] == v[i - 1]){
            cout << "NO";
            return 0;
        }
        cout << "YES";
    }
    return 0;
}


Measured memory_bytes: 1024
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int r, c, n;
int x[maxn], y[maxn], a[maxn];
int g[maxn][4];
int  used[maxn], usedc[maxn], usedr[maxn];
long long v[maxn], u[maxn];
long long minv, minu;
vector< pair<int, int> > rows[maxn], cols[maxn];

int read() {
  if (scanf("%d%d%d", &r, &c, &n) < 3) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &x[i], &y[i], &a[i]);
    x[i]--;
    y[i]--;
  }
  return true;
}

bool dfs(int i) {
  minv = min(minv, v[x[i]]);
  minu = min(minu, u[y[i]]);
  used[i] = true;
  for (int ii = 0; ii < 4; ii++) {
    int j = g[i][ii];
    if (j == -1 || used[j]) {
      continue;
    }
    if (ii & 1) {
      int vv = v[x[i]] + a[j] - a[i];
      if (usedr[x[j]] && v[x[j]] != vv) {
        return false;
      }
      v[x[j]] = vv;
      usedr[x[j]] = true;
      if (!dfs(j)) {
        return false;
      }
    } else {
      int uu = u[y[i]] + a[j] - a[i];
      if (usedc[y[j]] && u[y[j]] != uu) {
        return false;
      }
      u[y[j]] = uu;
      usedc[y[j]] = true;
      if (!dfs(j)) {
        return false;
      }
    }
  }
  return true;
}

void solve() {
  for (int i = 0; i < r; i++) {
    rows[i].clear();
    usedr[i] = false;
  }
  for (int i = 0; i < c; i++) {
    cols[i].clear();
    usedc[i] = false;
  }
  for (int i = 0; i < n; i++) {
    rows[x[i]].push_back(make_pair(y[i], i));
    cols[y[i]].push_back(make_pair(x[i], i));
    for (int j = 0; j < 4; j++) {
      g[i][j] = -1;
    }
  }
  for (int i = 0; i < r; i++) {
    sort(rows[i].begin(), rows[i].end());
    for (int j = 0; j + 1 < sz(rows[i]); j++) {
      g[rows[i][j].second][0] = rows[i][j + 1].second;
      g[rows[i][j + 1].second][2] = rows[i][j].second;
    }
  }
  for (int i = 0; i < c; i++) {
    sort(cols[i].begin(), cols[i].end());
    for (int j = 0; j + 1 < sz(cols[i]); j++) {
      g[cols[i][j].second][1] = cols[i][j + 1].second;
      g[cols[i][j + 1].second][3] = cols[i][j].second;
    }
  }
  for (int i = 0; i < n; i++) {
    used[i] = false;
  }
  for (int i = 0; i < n; i++) {
    if (used[i]) {
      continue;
    }
    v[x[i]] = 0;
    u[y[i]] = 0;
    usedr[x[i]] = true;
    usedc[y[i]] = true;
    minv = 0;
    minu = 0;
    if (!dfs(i) || a[i] + minu + minv < 0) {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 16640
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
if a[0] > x:
    ans = a[0]-x
    a[0] = x
for i in range(1, n):
    if a[i]+a[i-1] > x:
        d = a[i]+a[i-1]-x
        a[i] -= d
        ans += d
print(ans)


Measured memory_bytes: 14252
#include<iostream>

using namespace std;

int main(){
    
    int n;
    cin >> n;
    
    int array[n];
    
    for (int i = 0; i < n; ++i){
        cin >> array[i];
    }
    
    
    //print out
    cout << array[n-0-1];
    
    for (int i = 1; i < n; ++i){
        cout << " " << array[n-i-1];
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3088
def find_pos(board, n)
  @h.times do |y|
    @w.times do |x|
      return [x, y] if board[y][x] == n
    end
  end
end

def in_check(x, y)
  0 <= x && x < @w && 0 <= y && y < @h
end

def can_move(cx, cy, mx, my, board)
  used = @h.times.map{ [false] * @w }
  used[my][mx] = true
  queue = [[mx, my]]
  until queue.empty?
    x, y = queue.shift
    @dir.each do |dx, dy|
      xx = x + dx; yy = y + dy
      if in_check(xx, yy) && !used[yy][xx] &&
        board[yy][xx] != 1 && !(cx == xx && cy == yy)
        queue << [xx, yy]
        used[yy][xx] = true
      end
    end
  end
  used
end

def move(cx, cy, mx, my, board)
  ret = []
  move_pos = can_move(cx, cy, mx, my, board)
  @dir.each_with_index do |(dx, dy), i|
    x = cx + dx; y = cy + dy
    if in_check(x, y) && move_pos[y][x]
      ret << i
    end
  end
  ret
end

def solve(cx, cy, mx, my, board)
  used = @h.times.map{ @w.times.map{ [false] * 4 } }
  queue = []
  move(cx, cy, mx, my, board).each do |i|
    queue << [cx, cy, i, 0]
    used[cy][cx][i] = true
  end
  until queue.empty?
    x, y, i, n = queue.shift
    return n if x == @gx && y == @gy
    move(x, y, x + @dir[i][0], y + @dir[i][1], board).each do |i|
      xx = x + @dir[(i + 2) % 4][0]
      yy = y + @dir[(i + 2) % 4][1]
      if in_check(xx, yy) && !used[yy][xx][i] &&
        board[yy][xx] != 1
        queue << [xx, yy, i, n + 1]
        used[yy][xx][i] = true
      end
    end
  end
  -1
end

@dir = [[-1, 0], [0, 1], [1, 0], [0, -1]]
loop do
  @w, @h = gets.split.map(&:to_i)
  break if @w == 0
  board = @h.times.map{ gets.split.map(&:to_i) }

  cx, cy = find_pos(board, 2)
  @gx, @gy = find_pos(board, 3)
  mx, my = find_pos(board, 4)

  puts solve(cx, cy, mx, my, board)
end

Measured memory_bytes: 8824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

template <class S, class DP>
int f(int n, int x, const S& s, DP& dp) {
    if (n == 1) return x % s[n - 1];
    if (dp[n][x] >= 0) return dp[n][x];

    ll r = 0;
    r += f(n - 1, x % s[n - 1], s, dp);
    r += f(n - 1, x, s, dp) * (ll)(n - 1);
    return dp[n][x] = r % P;
}

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

    int n, x;
    cin >> n >> x;

    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());

    vector<vector<int>> dp(n + 1, vector<int>(x + 1, -1));

    cout << f(n, x, s, dp) << endl;

    return 0;
}

Measured memory_bytes: 79488
//a<b<c
#include<stdio.h>

int main()
{
	int a[3];
	int i,k,keep;

	scanf("%d %d %d",&a[0],&a[1],&a[2]); //3?????°??\???

	for(i=0;i<3;i++){				//????????????	
		for(k=i;k<3;k++){
			if(a[i]>a[k]){
					keep=a[i];
					a[i]=a[k];
					a[k]=keep;
				}
			}
		}

	printf("%d %d %d\n",a[0],a[1],a[2]);		//??????

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>

using namespace std;

struct edge { int to, cost; };
typedef pair<int, int> P;

const int MAX_V = 10000;
const int INF = 1 << 28;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

int prim(){
	int res = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	for(int s = 0;s < V; ++s) {
		if(d[s] != INF) continue;
		d[s] = 0;
		que.push(P(0, s));
		while(!que.empty()){
			P p = que.top(); que.pop();
			int v = p.second;
			if(d[v] < p.first) continue;
			d[v] = -INF;
			res += p.first;
			for(int i=0;i<G[v].size();i++){
				edge e = G[v][i];
				if(d[e.to] > e.cost){
					d[e.to] = e.cost;
					que.push(P(e.cost, e.to));
				}
			}
		}
	}
	return res;
}

int main(){
	int E;
	cin >> V >> E;
	for(int i=0;i<E;i++){
		int s, t, w;
		cin >> s >> t >> w;
		assert(0 <= s && s < V);
		assert(0 <= t && t < V);
		G[s].push_back((edge){t, w});
		G[t].push_back((edge){s, w});
	}
	cout << prim() << endl;
	return 0;
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 998244353;
constexpr int MAX_N = 3e5;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(MAX_N);

ll mod_pow(ll x, ll n, ll mod){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}

int main(){
  int n, m, k;
  cin >> n >> m >> k;

  mint res = 0;
  for (int i = 0; i <= k; i++) {
    res += (mint)m * (mint)mod_pow(m-1, n - 1 - i, mod) * comb(n - 1, i);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 7820
A, B = map(int, input().split())
N = B - A + 1
if A % 2 ==0:
	ans = (N // 2) % 2
	if N % 2 == 1:
		ans ^= B
else:
	ans = A ^ ((N - 1) // 2) % 2
	if N % 2 == 0:
		ans ^= B

print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<60)
#define EPS (1e-10)
#define end ______end
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n;
Int a[20][20];

Int cost[1 << 16];
Int dp[1 << 16];

int main(){
  fill(dp, dp + (1<<16), -INF);
  cin >> n;
  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      cin >> a[i][j];

  for(int i = 1;i < (1<<n);i++){
    int last = 0;
    while((i&-i) != (1<<last))last++;
    cost[i] = cost[i - (1<<last)];
    for(int j = 0;j < n;j++){
      if((i >> j) % 2 == 0)continue;
      cost[i] += a[last][j];
    }
  }

  Int mask = (1 << n) - 1;
  dp[0] = 0;
  for(int i = 0; i < (1 << n);i++){
    int rem = mask ^ i;
    for(int j = rem;j > 0;j = (j-1) &rem){
      dp[i | j] = max(dp[i | j], dp[i] + cost[j]);
    }
  }

  cout << dp[mask] << endl;
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.length(),j,k;
  vector<int> v(26,-1);
  for(j=0;j<l;j++){
    k=s[j]-'a';
    if(v[k]==-1||j-v[k]>2) v[k]=j;
    else{
      cout<<v[k]+1<<' '<<j+1<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}

Measured memory_bytes: 3768
N = int(input())
L = list(map(int,input().split()))
for i in range(N):
  L[i] = L[i]-i-1
L.sort()
S = 0
if len(L)%2 != 0:
  k = L[len(L)//2]
else:
  k = (L[len(L)//2-1]+L[len(L)//2])//2
for i in range(len(L)):
  S += abs(L[i]-k)
print(S)

Measured memory_bytes: 26020
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int a[n + 1];
        int pre[n + 1];
        pre[0] = 0;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            pre[i] = __gcd(pre[i - 1], a[i]);
        }
        int suff[n + 2];
        suff[n + 1] = 0;
        for(int i = n; i >= 1; i--){
            suff[i] = __gcd(suff[i + 1], a[i]);
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            ans = max(ans, __gcd(pre[i - 1], suff[i + 1]));
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 33920
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    auto S = sread();
    foreach (i; 0 .. S.length)
        if ((i & 1) == 0)
            write(S[i]);
    writeln();
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  for (int a = 1; a <= 9; ++a) {
    if (n % a == 0) {
      int b = n / a;
      if (1 <= b && b <= 9) {
        out("Yes");
        return 0;
      }
    }
  }
  out("No");
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <functional>
#include <string.h>

using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
int a[205];

int main(){
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	while (1) {
		bool flg = true;
		rep(i, n) {
			flg &= (a[i] % 2 == 0);
		}
		if (!flg)
			break;
		ans++;
		rep(i, n) {
			a[i] = a[i] / 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
int func2(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }
  return sum;
}

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int sumb=0,suma=0;
  for(int i=1;i<=n;i++){
    if(func2(i)<=b){sumb+=i;}
    if(func2(i)<=a-1){suma+=i;}
  }
  cout<<sumb-suma<<endl;
  return 0;
}

Measured memory_bytes: 256