akhauriyash/Code-Regression huggingface dataset:
//    Unmesh Kumar
//    CSE'22 IIT Roorkee

#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iterator>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>

using namespace std;
#define ll long long int
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl
#define debug2(a,b) cout<<" :: "<<#a<<" == "<<a<<" :: "<<#b<<" == "<<b<<endl
typedef pair<int,int> ii;
typedef vector<ii> vii;

inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }


ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}

int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

bool comp(ll a,ll b)
{
  return a>b;
}

ll arr[1000005];
ll a[1000005];
ll b[1000005];

int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  cc(a,b);
  bool boo =false;
  fr(o,1,10000)
  {
    if((ll)(floor(o*0.08)==a)&&(ll)(floor(o*0.1)==b))
    {
      boo=true;
      cout<<o<<endl;
      break;
    }
  }
  if(!boo) cout<<-1<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

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

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

int main(void){
  char a,b; cin>>a>>b;
  cout<<((a=='H')^(b=='H')?"D":"H");
}














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

using namespace std;


 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//5
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){

ios::sync_with_stdio(false);
cin.tie(0);
long long int x;
cin>>x;
long long int count=0;
long long int res=100;

while(true){
count++;
res*=1.01;
if(res>=x)break;
}
cout<<count<<endl;

}



//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

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

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  vi g1(N),g2(N);
  rep(i,N-1) {
    int x=A[i],y=g1[i];
    if(x<y) swap(x,y);
    g1[i+1]=gcd(x,y);
    x=A[N-i-1],y=g2[i];
    if(x<y) swap(x,y);
    g2[i+1]=gcd(x,y);
  }
  
  int ans=0;
  rep(i,N) ans=max(ans,gcd(g1[i],g2[N-i-1]));
  
  cout << ans << endl;
}

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

int main(){
    int ap, a0, am, k;
    cin >> ap >> a0 >> am >> k;
    if ( a0 == 0 && am == 0) {
        cout << k << endl;
        return 0;
    }
    long long ans = 0;
    for(int i = 0; i<k; i++) {
        if( ap > 0 ) {
            ap--;
            ans++;
        }
        else if(a0 > 0 ) {
            a0--;
        }
        else {
            am--;
            ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
N=int(input())
A = list(map(int, input().split()))
i = 0
sum = 0
while i<N-1:
  if A[i]<=A[i+1]:
    f=0
  else:
    f=A[i]-A[i+1]
  A[i+1]+=f
  sum+=f
  i+=1
print(sum)

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

int par[100005];
int rnk[100005];

void init(int n) {
  for (int i=0; i<n; i++) {
    par[i]=-1;
    rnk[i]=0;
  }
}
int find(int x) {
  if (par[x]<0) {
    return x;
  }
  else {
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y) {
  x=find(x);
  y=find(y);
  if (x==y) return;
  if (rnk[x]<rnk[y]) {
    par[y]+=par[x];
    par[x]=y;
  }
  else {
    par[x]+=par[y];
    par[y]=x;
    if (rnk[x]==rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y) {
  return find(x)==find(y);
}


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

  init(n);
  ll ans=(ll)n*(n-1)/2;
  ll memo[100005];
  memo[m-1]=ans;
  int a[100005],b[100005];
  rep(i,m) {
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
  }
  reverse(a,a+m); reverse(b,b+m);
  rep(i,m-1) {
    if (!same(a[i],b[i])) {
      ans-=(ll)par[find(a[i])]*par[find(b[i])];
    }
    unite(a[i],b[i]);
    memo[m-2-i]=ans;
  }
  rep(i,m) cout<<memo[i]<<endl;
  return 0;
}

Measured memory_bytes: 3712
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{s:String};
    println!("{} {}", &s[0..4], &s[4..]);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <deque>
 
using namespace std;
 
int main(){
  int a, n;
  deque<int> b;
  
  cin >> n;
  
  for(int i=1; i<=n; i++){
    cin >> a;
    if((n%2)==(i%2)){
      b.push_front(a);
    }else{
      b.push_back(a);
    }
  }
  
  for(int i=0; i<n-1; i++){
    cout << b[i] << " ";
  }
  cout << b[n-1] << endl;
}

Measured memory_bytes: 2944
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int K; cin >> K;
    int A , B; cin >> A >> B;
    for(int i=A; i<=B; i++) {
        if(i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, res = 0;
  cin >> n;
  vector<ll> a(n), l(n + 1), r(n + 1);

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

  for (int i = 0; i < n; ++i) l[i + 1] = gcd(a[i], l[i]);
  for (int i = n - 1; i >= 0; --i) r[i] = gcd(a[i], r[i + 1]);

  for (int i = 0; i < n; ++i) res = max(res, gcd(l[i], r[i + 1]));

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string s1 = Console.ReadLine();
        string s2 = Console.ReadLine();
        long count;
        bool state;
        int i;
        if(s1[0] == s2[0]){
            count = 3;
            state = true;
            i = 1;
        }
        else{
            count = 6;
            state = false;
            i = 2;
        }
        for(;i<N;i++){
            if(s1[i] == s2[i]){
                if(state){
                    count = count * 2 % Define.mod;
                }
                state = true;
            }
            else{
                if(state){
                    count = count * 2 % Define.mod;
                }
                else{
                    count = count * 3 % Define.mod;
                }
                state = false;
                i++;
            }
        }
        sb.Append(count+"\n");
    }
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 13140
from collections import defaultdict

N = int(input())
MOD = 10 ** 9 + 7

dp = [defaultdict(int) for i in range(N + 1)]
dp[0]['TTT'] = 1
for length in range(N):
    for c1 in 'ACGT':
        for c2 in 'ACGT':
            for c3 in 'ACGT':
                if dp[length][c3 + c2 + c1] == 0:
                    continue
                for c0 in 'ACGT':
                    if c2 + c1 + c0 in ['AGC', 'ACG', 'GAC']:
                        continue
                    if c3 + c1 + c0 == 'AGC':
                        continue
                    if c3 + c2 + c0 == 'AGC':
                        continue
                    dp[length + 1][c2 + c1 + c0] += dp[length][c3 + c2 + c1]

print(sum(dp[N].values()) % MOD)


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a.at(i);

	int cnt = 0;
	while(true) {
		bool flag = false;
		for(int i = 0; i < n; i++) {
			if(a.at(i) % 2 != 0) flag = true;
		}

		if(flag) break;

		for(int i = 0; i < n; i++) a.at(i) /= 2;

		cnt++;
	}

	cout << cnt << endl;

 	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int r,g,b,n;
    int ans = 0;
    scanf("%d%d%d%d", &r, &g, &b, &n);
    for(int i=0; i<=3000; i++){
        if(i*r > n) break;
        for(int j=0; j<=3000; j++){
            if(i*r + j*g <= n && (n-(i*r + j*g)) % b == 0) ans+=1;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll mo = 1000ll, k = 0ll;
	int n, v;
	cin >> n;
	vector<int> a;
	a.push_back(300);
	rep(i, 0, n) {
		cin >> v;
		if (v != a.back())a.push_back(v);
	}
	a.push_back(a.back() - 1);
	rep(i, 1, a.size() - 1) {
		if (a[i - 1] < a[i] && a[i] > a[i + 1]) {
			mo += k * a[i];
			k = 0ll;
		}
		else if (a[i - 1] > a[i] && a[i] < a[i + 1]) {
			k = mo / a[i];
			mo %= (ll)a[i];
		}
			//printf("k:%d mo:%d\n", k, mo);
	}
	printf("%lld\n", mo);
	return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
int main(){
    ll N;cin>>N;
    vector<pair<ll,int>> a(N);
    REP(i, N){ 
        cin >> a[i].first;
        a[i].second=i;
    }
    sort(All(a),[](const pair<ll,int> &a,const pair<ll,int> &b){
        if(a.first!=b.first) return a.first>b.first;
        else return a.second>b.second;
    });
    vector<ll> ans(N,0);
    ll j=1;
    int m=N;
    while(j<N){
        m=min(m,a[j-1].second);
        if(a[j].first==a[0].first) j++;
        else{
            ans[m]+=j*(a[0].first-a[j].first);
            a[0].first=a[j].first;
        }
        
    }
    ans[0]+=N*a[0].first;
    REP(i,N) cout<<ans[i]<<endl;
}

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

int main(){

	int cmb[8][3] = {{0,1,2}, {3,4,5}, {6,7,8},
									 {0,3,6}, {1,4,7}, {2,5,8},
									 {0,4,8}, {2,4,6}};
	string str;
	
	while(cin >> str){
		for(int i=0; i<8; i++){
			if(str[cmb[i][0]] != 's'){
				if(str[cmb[i][0]] == str[cmb[i][1]] && str[cmb[i][1]] == str[cmb[i][2]]){
					cout << str[cmb[i][0]] << endl;
					break;
				}
			}
			
			if(i == 7){
				cout << 'd' << endl;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 1172
import sys

s = list(input())

check_array = [0 for i in range(26)]

for i in range(len(s)):
    judge = s[i]
    
    for j in range(len(s)):
        if judge == check_array[j]:
            print("no")
            sys.exit()
    
    check_array[i] = judge

print("yes")


Measured memory_bytes: 2940
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f

int main()
{
    ll n;
    ll cnt[200050]={0};
    ll vis[200050]={0};
    scanf("%lld",&n);
    ll a[200050];
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        cnt[a[i]]++;
    }
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[a[i]])
        {
            sum+=cnt[a[i]]*(cnt[a[i]]-1)/2;
            vis[a[i]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        ll ans=sum;
        ans-=cnt[a[i]]*(cnt[a[i]]-1)/2;
        ans+=(cnt[a[i]]-1)*(cnt[a[i]]-2)/2;
        printf("%lld\n",ans);
    }
}


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

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

  string s = N;
  reverse(N.begin(), N.end());
  if (N == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	int t = 0;
	for(int i = a; i <= b; i++){
		if(!(c % i)){
			t++;
		}
	}
	printf("%d\n", t);
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, n;
	long  r[200002];

	cin >> n;

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

	long long maxx = -9999999999;
	long long minn = r[0];

	for (i = 1; i < n; i++) {
		
		maxx = max(maxx, (long long)r[i] - minn);
		minn = min(minn, (long long)r[i]);


	}

	cout << maxx << endl;










	getchar();
	getchar();
	return 0;
}

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int timeLimit = sc.nextInt();
        int[][] input = new int[N][2];
        List<Integer> list = new ArrayList<>();

        for(int i = 0; i < N; i++){
            for(int j = 0; j < 2; j++){
                input[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < N; i++) {
            if (input[i][1] <= timeLimit) {
                list.add(i);
            }
        }
        if (list.size() == 0){
            System.out.println("TLE");
        }else {
            int min = input[0][0];
            for (int k : list) {
                if (input[k][0] < min) {
                    min = input[k][0];
                }
            }

            System.out.println(min);
        }
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans;
    for(int pin = 0; pin <= 999; pin++) {
        stringstream ss;
        ss << setw(3) << setfill('0') << pin;
        int j = 0;
        for(int i = 0; i < N; i++) {
            if(S[i] == ss.str()[j]) {
                j++;
                if(j == 3) break;
            }
        }
        if(j == 3) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
fun main(args:Array<String>) {
  val (M, N) = readLine()!!.split(" ").map { x -> x.toLong() }
  val man = (1..M).map {
    readLine()!!.split(" ").map { x -> x.toLong() }
  }
  val checkpoints = (1..N).map {
    readLine()!!.split(" ").map { x -> x.toLong() }
  }
  val ans = man.map { x ->
    checkpoints.mapIndexed { i, cp ->
      val m = x.zip(cp).map { x2 ->
        val (x3, x4) = x2
        Math.abs(x3 - x4)
      }.reduce { x, y ->
        x + y
      }
      Pair(i+1, m)
    }.minBy { x ->
      val (i, m) = x
      m
    }
  }
  ans.map { a ->
   println(a!!.first)
  }
}

Measured memory_bytes: 30660
program B
    integer :: N, L, m = 1000000, mi = 0, s = 0, nm
    read*,N, L
    !$omp parallel
    do i = 0, N - 1, 1
        nm = L + i
        s = s + nm
        if (abs(nm) < m) then
            m = abs(nm)
            mi = nm
        endif
    enddo
    !$omp end parallel
    print*, s - mi
end program B

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    string s;

    for(int i=1;i<=n;i++)
    {
        s += "ACL";
    }
    cout << s << endl;
    return 0;

}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    vector<int>::iterator itr;
    for (int j = 1; j <= n; j++) {
        itr = find(a.begin(), a.end(), j);
        cout << distance(a.begin(), itr) + 1 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include <algorithm>
#include <limits>
#include <cmath> 
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;

    bool c=true;
    if(s[a]!='-')c=false;
    for(int i=0;i<a;i++){
        if('0'<=s[i]&&s[i]<='9');
        else c=false;
    }
    for(int i=1;i<=b;i++){
        if('0'<=s[i+a]&&s[i+a]<='9');
        else c=false;
    }
    if(c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

class Repeater{
    int st;
    int ed;
    int d;
public:
    class rep_iterator{
        int i; int d;
    public:
        rep_iterator(int x, int pd) :i(x), d(pd) {}

        int& operator*(){ return i; }
        bool operator==(const rep_iterator& k) const { return i == k.i; }
        bool operator!=(const rep_iterator& k) const { return i != k.i; }
        rep_iterator& operator++(){ i+=d; return *this; }
    };

    Repeater(int N) :st(0), ed(N), d(1) {}
    Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }
    Repeater(int b, int e, int dif) :st(b), ed(e), d(dif) {}

    rep_iterator begin() const{ return rep_iterator(st, d); }
    rep_iterator end() const{ return rep_iterator(ed, d); }

};

template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
template<class T> using min_queue = p_queue<T, greater<T>>;
template<class T> using max_queue = p_queue<T, less<T>>;

template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

void sub_main(istream &cin) {
    ll N, L;
    cin >> N >> L;
    if(!cin) return;
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += L + i;
    }// i
    ll optim = INF;
    ll optimI = -1;
    for (int i = 0; i < N; ++i) {
        ll dif = abs(L + i);
        if(dif < optim){
            optim = dif;
            optimI = i;
        }
    }// i
    cout << sum - optimI - L << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_B.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


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

// https://atcoder.jp/contests/abc165/tasks/abc165_c
public class Main {
	static int[] arrayA;
	static int[] arrayB;
	static int[] arrayC;
	static int[] arrayD;

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();

		arrayA = new int[q];
		arrayB = new int[q];
		arrayC = new int[q];
		arrayD = new int[q];

		for (int i = 0; i < q; i++) {
			arrayA[i] = sc.nextInt();
			arrayB[i] = sc.nextInt();
			arrayC[i] = sc.nextInt();
			arrayD[i] = sc.nextInt();
		}
		sc.close();

		Integer[] array = {};
		System.out.println(dfs(array, n, m));
	}

	static int score(Integer[] array) {
		int ans = 0;
		for (int i = 0; i < arrayB.length; i++) {
			if (array[arrayB[i] - 1] - array[arrayA[i] - 1] == arrayC[i]) {
				ans = ans + arrayD[i];
			}
		}
		return ans;
	}

	//////////////////
	static int dfs(Integer[] array, int N, int M) {
		if (array.length == N) {
			return score(array);
		}

		int last_i;
		if (array.length > 0) {
			last_i = array[array.length - 1];
		} else {
			last_i = 1;
		}

		int ans = 0;
		for (int i = last_i; i <= M; i++) {
			List<Integer> list = new ArrayList<>(Arrays.asList(array));
			list.add(i);
			array = list.toArray(new Integer[list.size()]);
			ans = Math.max(ans, dfs(array, N, M));
			list.remove(list.size() - 1);
			array = list.toArray(new Integer[list.size()]);
		}
		return ans;
	}
	//////////////////
}

Measured memory_bytes: 46400
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a[5];

int f(int x){
  int b = 10 - x%10;
  return x + (x%10 ? b : 0);
}

int main(){
  int ans=0;
  int m=10;
  REP(i,5){
    cin>>a[i];
    ans+=f(a[i]);
    int b = a[i]%10;
    if(b<m && b>0) m = b;
  }
  ans -= 10 - m;
  cout<<ans<<endl;
  return 0;
}


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

int mod_pow(ll a, int n, int m) {
    ll b, t;
    if (n == 0) {
        return 1;
    }

    a %= m;
    b = a * a;
    b %= m;

    t = mod_pow(b, n / 2, m);
    if (n % 2 != 0) {
        t *= a;
        t %= m;
    }

    return t;
}

int main() {

    int M, N;
    cin >> M >> N;

    cout << mod_pow(M, N, INF + 7) << endl;

    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int r,g,b;
    cin>>r>>g>>b;
    if((10*g+b)%4==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}   




Measured memory_bytes: 256
n,a,b,c=map(int, input().split())
x=[int(input()) for i in range(n)]
from itertools import product
z=[a,b,c]
d=[0,1,2,3]
ans=10**8
for i in product(d,repeat=n):
    an=0
    y=[[],[],[],[]]
    for j,k in enumerate(i):
        y[k].append(x[j])
    if len(y[1])==0 or len(y[2])==0 or len(y[3])==0:continue
    for k,j in enumerate(y[1:]):
        an+=(len(j)-1)*10+abs(sum(j)-z[k])
    ans=min(an,ans)
print(ans)

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

int N;
string S;

int dp[5000][5000];

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

  for(int i=N-1; i>=0; i--) for(int j=N-1; j>=0; j--) {
    if(S[i]==S[j]) dp[i][j] = 1 + (((i<N-1)&&(j<N-1)) ? dp[i+1][j+1] : 0);
    else dp[i][j] = 0;
  }

  int ans = 0;
  for(int i=0; i<N; i++) {
    for(int j=i; j<N; j++) {
      if(dp[i][j] <= j-i) ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 97920
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    int i = 0;
    int N = s.length();
    long long int result = 0;
    int count_A = 0;
    while (i < N - 2) {
        if (s[i] == 'A') {
            count_A++;
            if (s.substr(i, 3) == "ABC") {
                result += count_A;
                s[i + 2] = 'A';
                count_A--;
                i++;
            }
        } else {
            count_A = 0;
        }
        i++;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

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

      List<Integer> nums = new ArrayList<>();
      nums.add(0);
      for(int i = 1; i <=n; i++)
        nums.add(sc.nextInt());

      List<Integer> result = new ArrayList<>();
      while(nums.size() > 1) {
        int idx = -1;
        for(int i = 1; i < nums.size(); i++) {
          if(nums.get(i) > i) {
            System.out.println(-1);
            return;
          }
          if(nums.get(i) == i)
            idx = i;
        }
        
        result.add(nums.get(idx));
        nums.remove(idx);
      }
      for(int i = result.size() - 1; i >= 0; i--)
        System.out.println(result.get(i));
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<int> vi;
const int MOD=1000000007;

int n,m,x,y,a,b;

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

	cin>>n>>m>>x>>y;
	for(int i=1;i<=n;i++){
		cin>>a;
		x=max(x,a);
	}
	for(int i=1;i<=m;i++){
		cin>>b;
		y=min(y,b);
	}
	puts(x<y ? "No War" : "War");

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
ll h, w, n, a, b, c[15], E=1e9;
map<ll,ll> mp;
int main() {
	ll i, j, k;
	scanf("%d%d%d", &h, &w, &n);
	c[0] = (h-2) * (w-2);
	while(n--) {
		scanf("%d%d", &a, &b);
		for(i=a; i<a+3; i++) for(j=b; j<b+3; j++) {
			if(i>2 && j>2 && i<=h && j<=w) {
				k = mp[i*E+j]++;
				c[k]--; c[++k]++;
			}
		}
	}
	for(i=0; i<=9; i++) printf("%lld\n", c[i]);
	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <string>

int calculateDiditSum(std::string str)
{
    int sum = 0;
    int count = str.length();
    for(int i = 0; count > i;i++)
    {
        sum+= atoi(str.substr(i,1).c_str());

    }
    return sum;
}

int main()
{
    std::string str;
    std::string ansYes("Yes"),ansNo("No");
    // インプット
    std::cin >> str;
    int sumDigits = 0;

    //桁の合計

    sumDigits = calculateDiditSum(str);
    if (sumDigits % 9 == 0)
    {
        std::cout << ansYes;
    }
    else {
        std::cout << ansNo;
    }

}

Measured memory_bytes: 3780
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    long long A=0;
    vector<int>B(N-1);
    rep(i, N - 1)cin >> B[i];
    A += B[0]+B[N-2];
    REP(i, N - 1)A += min(B[i - 1], B[i]);
    cout << A << endl;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define lli long long int

int main()
{
        lli n, x, ans = 0, count = 0;
        cin >> n;
        // cin >> x;
        lli a[n];
        for(int i=0;i<n;i++)
            cin >> a[i];
        if(n<3)
        {
            cout << 0 << endl;
            return 0;
        }
        for(int i=0;i<n-2;i++)
        {
            for(int j=i+1;j<n-1;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
                    {
                        if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i])
                            count++;
                    }
                }
            }
        }
        cout << count << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }

// #define int long long

using namespace std;

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

  int num = 0;
  int a; cin >> a;
  int b; cin >> b;
  int k; cin >> k;
  vector<int> v;
  
  for (int i = 1; i <= min(a, b); ++i) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }

  num = v[v.size()  - k];
  
  cout << num << endl;

  return 0;
}


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

bool dp[1005][1005][1005];

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

    int a,b;
    cin >> a >> b;
    if(a <= b) cout << a << endl;
    else cout << a-1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, p;
	cin >> n >> p;
	vi a(n);
	rep(i, n) cin >> a[i];
	int evn = 0, odd = 0;
	rep(i, n) (a[i] & 1 ? odd : evn)++;
	ll ans = 0;
	if(odd) ans = pow(2, n-1);
	else if(!p) ans = pow(2, n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def count_ones(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count


def main():
    N = int(readline())
    X = []
    for i in range(N):
        A = int(readline())
        tmp = []
        for _ in range(A):
            tmp.append(tuple(map(int, readline().split())))
        X.append(tmp)

    ans = 0
    for i in range(2**N):
        OK = True
        for j in range(N):
            if ((i >> j) & 1):
                for x in X[j]:
                    if ((i >> (x[0] - 1)) & 1) != x[1]:
                        OK = False
                        break
                if not OK:
                    break
        if OK:
            ans = max(ans, count_ones(i))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())[::-1]
slen = len(S)
T = list(input())[::-1]
tlen = len(T)

for i in range(slen):
    for j in range(tlen):
        if i+j>=slen:
            break
        if not (S[i+j]=='?' or S[i+j]==T[j]):
            break
    else:
        for j in range(tlen):
            S[i+j] = T[j]
        S = [s if not s=='?' else 'a' for s in S[::-1]]
        print(''.join(S))
        break
else:
    print('UNRESTORABLE')

Measured memory_bytes: 9152
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


h, w = inl()
h2, w2 = inl()

print(h * w - h2*w - w2*h + h2*w2)


Measured memory_bytes: 3572
MAXN = 2*10**6+2
p = 10**9 + 7

fact = [1] * MAXN
invfact = [1] * MAXN
for i in range(1, MAXN):
    fact[i] = fact[i-1] * i % p
invfact[MAXN-1] = pow(fact[MAXN-1], p-2, p)
for i in range(MAXN-1, 0, -1):
    invfact[i-1] = invfact[i] * i % p
    
def nCk(n, k):
    return fact[n] * invfact[n-k] * invfact[k] % p

K = int(input())
N = len(input())

ans = 0
for i in range(N, N+K+1):
    ans += pow(25, i-N, p) * nCk(i-1, N-1) * pow(26, N+K-i, p) % p
    ans %= p
print(ans)


Measured memory_bytes: 117204
N = int(input())
A = list(map(int,input().split()))

if all(a==0 for a in A):
    print(0)
    exit()

INF = float('inf')
mn = INF
mx = -INF
mni = mxi = -1
for i,a in enumerate(A):
    if a > mx:
        mx = a
        mxi = i
    if a < mn:
        mn = a
        mni = i

ans = []
if mn >= 0:
    p = True
elif mx <= 0:
    p = False
else:
    if mx > -mn:
        for i,a in enumerate(A):
            if a < 0:
                ans.append((mxi+1, i+1))
        p = True
    else:
        for i,a in enumerate(A):
            if a > 0:
                ans.append((mni+1, i+1))
        p = False

if p:
    for i in range(1,N):
        ans.append((i,i+1))
else:
    for i in range(N,1,-1):
        ans.append((i,i-1))

print(len(ans))
for a,b in ans:
    print(a,b)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

int main(){
	int N;
	cin>>N;
	bool flag = false;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		if(a%2==1){
			flag=true;
		}
	}
	if(flag)cout<<"first"<<endl;
	else cout<<"second"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N, K, S;
    cin >> N >> K >> S;

    ll s = S;
    ll mode = 0;
    ll cnt = 0;

    vector<ll> ans;
    for (ll i = 0; i < N; i++)
    {
        if (i < K) {
            cout << S;
        } else {
            if (S == 1000000000) {
                cout << 1;
            } else {
                cout << 1000000000;
            }
        }
        if (i == N - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
    
    for (ll i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
        if (i == ans.size() - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

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

int main()
{
    int n = 0;
    std::cin >> n;
    
    std::vector<int> array(n);
    
    int allXOR = 0;
    for(int index = 0; index < n; ++index)
    {
        std::cin >> array.at(index);
        allXOR ^= array.at(index);
    }
    
    std::string resultString;
    
    for(int index = 0; index < n; ++index)
    {
        resultString += std::to_string(allXOR ^ array.at(index)) + ' ';
    }
    
    resultString.pop_back();
    
    std::cout << resultString << std::endl;   
}

Measured memory_bytes: 6660
#include<stdio.h>
#define M 100000

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

int main(){
  int n,i,A[M+1];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d",i);
    printf(": key = %d, ",A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=n)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=n)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.nextLine();
		String str2 = sc.nextLine();
		String str3 = sc.nextLine();
		String str4 = sc.nextLine();

		int a = Integer.parseInt(str1);
		int b = Integer.parseInt(str2);
		int c = Integer.parseInt(str3);
		int d = Integer.parseInt(str4);

		int train;
		int bus;

		if(a > b) {
			train = b;
		}else {
			train = a;
		}


		if(c > d) {
			bus = d;
		}else {
			bus = c;
		}

		System.out.println(train+bus);


		sc.close();
	}

}

Measured memory_bytes: 21844