akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(ans - (cnt - m)*ab[i-1][0])

Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;

string str;
string a, b;
int32_t main()
{
	int n;
	cin >> n;
	cin >> str;
	for (int i = 0; i<str.size()/2; i++)
		a.push_back(str[i]);
	for (int i = str.size()/2; i<str.size(); i++)
		b.push_back(str[i]);
	cout << ((a == b)?"Yes\n":"No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) { 
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main(){
    int n;
    cin >> n;
    map<ll, int> woods;
    rep(i, n) {
        ll a;
        cin >> a;
        woods[a]++;
    }

    pair<ll, ll> wh{-1, -1};
    for (auto iter=woods.rbegin();iter!=woods.rend();iter++) {
        if (wh.first != -1 && wh.second != -1) break;

        if ((*iter).second >= 4) {
            wh.first = max(wh.first, (*iter).first);
            wh.second = max(wh.second, (*iter).first);
        } else if ((*iter).second >= 2) {
            if (wh.first == -1) wh.first = (*iter).first;
            else if (wh.second == -1) wh.second = (*iter).first;
        }
    }

    if (wh.first != -1 && wh.second != -1) cout << (wh.first * wh.second) << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 6528
import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Main{
    public static void main(String[] a){
    	int weight = 0;
    	
    	Scanner scan = new Scanner(System.in);
    	while (scan.hasNext()){
    	weight = scan.nextInt();
    	int[] omori = {1,2,4,8,16,32,64,128,256,512};
    	String kotae = "";
    	int keisan = weight;
    	for(int i = omori.length -1;i >= 0;i--){
    		if(keisan >= omori[i]){
    			keisan = keisan - omori[i];
    		}else{
    			omori[i] = 0;
    		}
    	}
    	for(int k = 0;k < omori.length;k++){
    		if(omori[k] > 0){
    			kotae += omori[k] + " ";
    		}
    	}
    	System.out.println(kotae.trim());
    	}
    	
    	}
 }

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

int tax(int money, double p){
    return int(money*p);
}

int main(){
    int a,b;
    cin >> a >> b;
    int ans = -1;
    for(int i=0;i<100000;i++){
        if(tax(i,0.08)==a && tax(i,0.1)==b){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int a,b;
  cin >> a >> b;
  if(a==b){
    cout << "a == b" << endl;
  } else if(a<b){
    cout << "a < b" << endl;
  } else{
    cout << "a > b" <<endl;
  }
   return 0;
}

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

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

    char a; cin >> a;

    if (isupper(a)) cout << 'A' << endl;
    else cout << 'a' << endl;

    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            String c = "";
            if(m == -1 || f == -1) c = "F";
            else if(m + f >= 80)   c = "A";
            else if(m + f >= 65)   c = "B";
            else if(m + f >= 50)   c = "C";
            else if(m + f >= 30) {
                if(r >= 50) c = "C";
                else        c = "D";
            } else {
                c = "F";
            }
            System.out.println(c);
        }
    }
}

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

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

#define pll pair<ll,ll>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int INF = 1e9;
const ll mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}



void solve()
{
    int n; cin>>n;
    ll ans = 0;
    vi v;
    rep(i, n)
    {
        int x; cin>>x;
        v.pb(x);
        if(i != 0)
        {
            if(v[i] < v[i-1]) {
                ans += v[i-1]-v[i];
                v[i] = v[i-1];
            }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    // clock_t start, end;
    // start = clock();
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    int t = 1;
    // cin>>t;
    REP(i, 1, t)
    {
        solve();
        
    }
    // end = clock();
    // double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    // watch(time_taken);
    ll x = INF; x++;
    return 0;
    
}



/*before sub
TEST: 0(1 by 1 too), 1, equal, -ve, bounds(random and ez)
ERR/WA: loop vars, out of bounds, endl, finish taking inputs, large doubles, larger INF, corr mod, t, early/late mod
RE: double dec, integer overflow(ll or 1LL mult)
*/





Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int n;
    cin >> n;
    int dp[n+1][3];
    memset(dp, 0, sizeof dp);
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        vi vals = {a,b,c};
        rep(j, 3) {
            rep(k, 3) {
                if (j==k) continue;
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + vals[j]);
            }
        }
    }
    
    int mx = 0;
    rep(i, 3) mx = max(mx, dp[n][i]);
    cout << mx << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        //solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 4744
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
template <typename T> T max(T, T);
int gcd(int a, int b);

int main() {
    // source
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T max(T a, T b) {

    if (a > b) {
        return a;
    } else {
        return b;
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

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

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

int s[30];
bool ok[30];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int n;scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int x;scanf("%d",&x);
		s[x]++;
	}
	if (s[0]) {puts("0");return 0;}
	for (int i=1;i<12;i++)
	{
		if (s[i]>2) {puts("0");return 0;}
	}
	int ans=0;
	for (int i=0;i<(1<<12);i++)
	{
		memset(ok,0,sizeof(ok));ok[0]=1;
		for (int j=1;j<=12;j++)
		{
			if (s[j]==2) {ok[j]=1;ok[24-j]=1;}
			if (s[j]==1)
			{
				if (i&(1<<(j-1))) ok[j]=1; else ok[24-j]=1;
			}
		}
		int t=24;
		for (int j=0;j<24;j++)
			for (int k=j+1;k<24;k++)
				if (ok[j]&&ok[k]) t=min(t,min(k-j,24-k+j));
		ans=max(ans,t);
	}
	printf("%d\n",ans);	
	return 0;
}



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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
string s;
int dp[500010][3];

int main() {
	cin >> N >> s;
	vector<pii> vec;
	int c = -1;
	int cnt;

	rep(i, N) {
		if (c == -1) {
			cnt = 1;
			c = s[i];
		} else if (c == s[i]) {
			++cnt;
		} else {
			vec.eb(c, cnt);
			cnt = 1;
			c = s[i];
		}
	}
	vec.eb(c, cnt);

	N = vec.size();
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;

	rep(i, N) {
		dp[i+1][0] = max({dp[i+1][0], dp[i][0], dp[i][1], dp[i][2]});

		if (i + 2 >= N) continue;
		if (vec[i].fi == '0' || vec[i+1].se > 1) {
			continue;
		}

		rep(j, 3) {
			if (dp[i][j] == -1) continue; 
			rep(k, 3) {
				int ni = k > 0 ? i + 2 : i + 3;
				int l = (j == 2 ? 1 : (j == 1 ? vec[i].se - 1 : vec[i].se));
				int r = (k == 1 ? 1 : (k == 2 ? vec[i+2].se - 1 : vec[i+2].se));
				if (l == 0 || r == 0) continue;
				int add = (l == 0 || r == 0 ? 0 : max(l, r));
				dp[ni][k] = max(dp[ni][k], dp[i][j] + add);
			}
		}
	}

	cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

	return 0;
}

Measured memory_bytes: 8824
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,dp[6][5];
char s[20],*k="MARCH";
int main()
{
	cin >> n;
	long long cnt[5]={0};
	for(int i=0; i<n; i++)
	{
		cin >> s;
		char *v=strchr(k,s[0]);
		if(v) cnt[v-k]++;
	}
	for(int i=0; i<=5; i++) dp[i][0]=1;
	for(int i=1; i<=5; i++)
		for(int j=1; j<=3; j++)
			if(i>=j)
			{
				dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*cnt[i-1];
				//cout << dp[i][j]<< ' ';
			}
	cout << dp[5][3];
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int d,w;
  while(cin>>d>>w,d||w){
    int e[d][w];
    for(int i=0;i<d;i++)
      for(int j=0;j<w;j++)
	cin>>e[i][j];
    int ans=0;
    for(int i=0;i<d;i++){
      for(int j=0;j<w;j++){
	for(int k=i+2;k<d;k++){
	  for(int l=j+2;l<w;l++){
	    int lb=0;
	    for(int a=i+1;a<k;a++){
	      for(int b=j+1;b<l;b++){
		lb=max(lb,e[a][b]);
	      }
	    }
	    int ub=e[i][j];
	    for(int a=j;a<=l;a++){
	      ub=min(ub,e[i][a]);
	      ub=min(ub,e[k][a]);
	    }
	    for(int b=i;b<=k;b++){
	      ub=min(ub,e[b][j]);
	      ub=min(ub,e[b][l]);
	    }
	    if(lb>=ub) continue;
	    int tmp=0;
	    for(int a=i+1;a<k;a++){
	      for(int b=j+1;b<l;b++){
		tmp+=ub-e[a][b];
	      }
	    }
	    //cout<<lb<<" "<<ub<<":"<<tmp<<endl;
	    ans=max(ans,tmp);
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include <vector>

using namespace std;

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

  	vector<int> x(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i) ;
  }
	vector<int> ans(n);
  for(int i=0;i<n;i++){
    ans.at(x.at(i)-1) =  i+1 ;
  }

    for(int i=0;i<n;i++){
      cout << ans.at(i) << ' ' ; 
  }

  cout << endl;
	return 0;
}


Measured memory_bytes: 1664
n = int(input())
a = list(map(int, input().split()))
b = [-1] * (n + 1)
a.insert(0, 0)

for i in range(n, 0, -1):
    t_sum = 0
    j = 2 * i
    while j <= n:
        t_sum ^= b[j]
        j += i
    b[i] = t_sum ^ a[i]
print(sum(b[1:]))
for i in range(1, n + 1):
    if b[i] != 0:
        print(i, end = ' ')    

Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll countMax;
bool func(ll R, ll G, ll B, ll count){
    if ( count == countMax ){
        //cout << R << ":" << G << ":" << B << endl;
        return R<G && G < B;
    }
    if ( func(R*2, G, B, count+1) ) return true;
    if ( func(R, G*2, B, count+1) ) return true;
    if ( func(R, G, B*2, count+1) ) return true;
    return false;

}
int main()
{
    ll R,G,B;
    ll N;
    cin >> R >> G >> B;
    cin >> N;
    countMax = N;
    auto ans = func(R, G, B, 0)  ? "Yes" : "No";
    cout <<ans  << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f
#define PI acos(-1.0)

typedef long long ll;
const int maxn=1e6;
int a[maxn],b[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d%d",a+i,b+i);
    ll sum=0;
    for(int i=0;i<n;i++)
        if((k|a[i])==k)
            sum+=b[i];
    for(int i=0;i<=30;i++)
    {
        if((1<<i)&k)
        {
            ll ans=0;
            int t=(k-(1<<i))|((1<<i)-1);
            for(int j=0;j<n;j++)
            {
                if((t|a[j])==t)
                    ans+=b[j];
            }
            sum=max(sum,ans);
        }
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 4736
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)*}
    };
}
 
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)*}
    };
}
 
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")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! {
        x: usize, y: usize, z: usize, k:usize,
        a: [u64; x], 
        b: [u64; y],
        c: [u64; z]
    }
    let mut ans :Vec<u64> = vec![];
    let mut a = a;
    let mut b = b;
    let mut c = c;
    a.sort(); a.reverse();
    b.sort(); b.reverse();
    c.sort(); c.reverse();
    let mut ab = vec![];
    for i in 0..x {
        for j in 0..y {
            ab.push(a[i]+b[j]);
        }
    }
    ab.sort(); ab.reverse();
    let mut abc = vec![];
    for i in 0..std::cmp::min(x*y, k) {
        for j in 0..z {
            abc.push(ab[i]+c[j]); 
        }
    }
    abc.sort(); abc.reverse();
    for i in 0..k { println!("{}", abc[i]); }
}

Measured memory_bytes: 44280
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    string s; cin >> s;
    int n = s.size();
    if (n > 9) {
        cout << "NO" << endl;
        return 0;
    }
    for (int bit = 0; bit < (1 << (n+1)); bit++) {
        string t = "";
        rep(i, n+1) {
            if (bit & (1 << i)) t += 'A';
            if (i != n) t += s[i];
        }
        if (t == "AKIHABARA") {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Max 4000001
#define int long long
using namespace std;
struct tp{
    int m,h;
};
tp a[4000001];
long long d[1000001];
long long t,kq,n,b[4000001],cc,c[1000000],tmp;
long long sum[Max],qii,qjj;
struct segmemntree{
    int l[Max];
    int r[Max];
    int leaf[Max];
    void build(int i,int j,int id)
    {
        l[id]=i;
        r[id]=j;
        sum[id]=0;
        if(i==j)
        {
            leaf[i]=id;
            return;
        }
        int mid=(i+j)/2;
        build(i,mid,id*2);
        build(mid+1,j,id*2+1);
        sum[id]=sum[2*id]+sum[2*id+1];
    }
    void update(int pos,int val)
    {
        int x=leaf[pos];
        sum[x]=tmp+val;
        while(x>0)
        {
            x/=2;
            sum[x]=max(sum[2*x],sum[2*x+1]);
            tmp=max(tmp,sum[x]);
        }
        /*sum[leaf[pos]]=tmp+val;

        x=leaf[pos];
        while(x>0)
        {
            x/=2;
            sum[x]=max(sum[2*x],sum[2*x+1]);
        }*/
    }
    int qi,qj;
    int get(int x)
    {
        if(r[x]<qi||l[x]>qj)
            return 0;
        if(l[x]>=qi&&r[x]<=qj)
            return sum[x];
        else
        {
            return max(get(2*x),get(2*x+1));
        }
    }
    int gett(int x)
    {
        if(r[x]<qii||l[x]>qjj)
            return 0;
        if(l[x]>=qii&&r[x]<=qjj)
            return sum[x];
        else
        {
            return max(gett(2*x),gett(2*x+1));
        }
    }
    void hoi(int i,int j)
    {
        qi=i;
        qj=j;
        kq=max(get(1),kq);
    }
};
segmemntree tree;
signed  main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    cin>>n;
    tree.build(1,n,1);
    for(int i=1;i<=n;i++){
        cin>>a[i].m;
        c[i]=a[i].m;
    }
    for (int i=1;i<=n;i++)
        cin>>a[i].h;

    sort(c+1,c+1+n);
    for (int i=1;i<=n;i++)
    if (d[c[i]]==0){
        cc++;
        d[c[i]]=cc;
    }
   // int qii,qjj;
    for (int i=1;i<=n;i++){
        tmp=0;
        qii=1;
        qjj=d[a[i].m]-1;
        tmp=tree.gett(1);
        tree.update(d[a[i].m],a[i].h);
        tree.hoi(1,d[a[i].m]);
    }
    cout<<kq;
}



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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    bool chk[26];
    for(int i=0;i<26;i++) chk[i]=false;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++) chk[s[i]-'a']=true;
    for(char c='a';c<='z';c++){
        if(!chk[c-'a']){
            cout << (s+c) << endl;
            return 0;
        }
    }
    for(int i=s.size()-1;i>=1;i--){
        string t=s.substr(0,i);
        for(int j=0;j<26;j++) chk[j]=false;
        for(int j=0;j<i;j++) chk[s[j]-'a']=true;
        for(char c=t[i-1]+1;c<='z';c++){
            if(!chk[c-'a']){
                t[i-1]=c;
                cout << t << endl;
                return 0;
            }
        }
    }

    cout << "-1" << endl;

    return 0;
}

Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

bool arr[MAXN];

int n, m;

bool ans;

void solve() {
    scanf("%d %d", &n, &m);

    for (int i = 1, l, r; i <= m; ++i) {
        scanf("%d %d", &l, &r);

        if (l > r) {
            swap(l, r);
        }

        arr[l + 1] ^= 1;
        arr[r + 1] ^= 1;
    }

    ans = 1;

    for (int i = 1; i <= n; ++i) {
        arr[i] ^= arr[i - 1];
        ans &= (arr[i] == 0);
    }

    printf(ans ? "YES\n" : "NO\n");
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define Maxn 100005
using namespace std;
const int N=1e9+7;
bool Cmp(int a,int b){
    return a>b;
}
int main(){
    long long x[Maxn],y[Maxn],n,m,sumx=0,sumy=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int i=0;i<m;i++)
        cin>>y[i];
    sort(x,x+n,Cmp);
    sort(y,y+m,Cmp);
    for(int i=0;i<=n-1;i++){
        sumx=(sumx+(x[i]-x[i+1])*(n-1-i)*(i+1))%N;
 
    }
    for(int i=0;i<=m-1;i++){
        sumy=(sumy+(y[i]-y[i+1])*(m-1-i)*(i+1))%N;
    }
    cout<<sumx*sumy%N<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {
	int n,k;
	string s;
	cin>>n>>k>>s;

	s[k-1]=s[k-1]+32;
	cout<<s<<"\n";
	return 0;
}


Measured memory_bytes: 256
N=int(input())
D=list(map(int,input().split())) +[0]
from collections import Counter
cnt=Counter(D)

if cnt[0]>=2 or cnt[12]>=2:
    print(0)
    exit()

if any(v>=3 for v in cnt.values()):
    print(0)
    exit()

ans=0
for b in range(1<<11):
    ts=[0]*24
    ts[0]=1
    if cnt[12]:
        ts[12]=1
    for i in range(11):
        t=i+1
        if cnt[t]==0:
            continue
        if cnt[t]==2:
            ts[t]=ts[24-t]=1
            continue
        if b&(1<<i):
            ts[t]=1
        else:
            ts[24-t]=1
    tt=[i for i,b in enumerate(ts) if b]
    tmp=24-tt[-1]
    for t1,t2 in zip(tt,tt[1:]):
        tmp=min(tmp,t2-t1)
    ans=max(tmp,ans)
print(ans)

Measured memory_bytes: 42224
import sys


class DLLNode:
    __slots__ = ['prev', 'next', 'data']

    def __init__(self, prev, next, data):
        self.prev = prev
        self.next = next
        self.data = data


root = DLLNode(None, None, None)
cur = root.next = DLLNode(root, None, None)


def insert(x, cur):
    cur.prev.next = cur.prev = cur = DLLNode(cur.prev, cur, x)
    return cur


def move(x, cur):
    d = int(x)
    if d > 0:
        for _ in range(d):
            cur = cur.next
    else:
        for _ in range(-d):
            cur = cur.prev
    return cur


def erase(_, cur):
    cur.next.prev = cur.prev
    cur.prev.next = cur = cur.next
    return cur


C = {'0': insert, '1': move, '2': erase}
sys.stdin.readline()
for query in sys.stdin:
    cur = C[query[0]](query[2:], cur)

ans = []
it = root.next
while it.next:
    ans.append(it.data)
    it = it.next

sys.stdout.writelines(ans)


Measured memory_bytes: 69052
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N , M, X;
    cin >> N >> M >> X;
    vector<int> a(N,0);
    for(int i=0;i<M;i++){
        cin >> a[i] ;
    }//入力

    int countm=0;
    int countx=0;

    for(int j=0;j<M;j++){
        if(a[j]<X){
            countm++;
        }else{
            countx++;
        }
    }

    if(countm>countx){
        cout << countx << endl;
    }else{
        cout << countm <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	ll all = 1;
	for (int i = 0; i < n; i++) {
		all *= 10;
		all %= MOD;
	}
	ll x = 1;
	for (int i = 0; i < n; i++) {
		x *= 9;
		x %= MOD;
	}
	ll y = 1;
	for (int i = 0; i < n; i++) {
		y *= 8;
		y %= MOD;
	}
	x = (all + MOD - x) % MOD;
	// y = (all + MOD - y) % MOD;
	// cout << x << " " << y << endl;
	ll ans = (all + MOD - (y + x) % MOD) % MOD;
	ans = (x + MOD - ans);
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        String str = sc.nextLine();

        for(int i=0;i<3;i++) {
            if(str.charAt(i) == str.charAt(i+1)) {
                pw.println("Bad");
                pw.close();
                return;
            }
        }
        pw.println("Good");
        pw.close();
    }
}

Measured memory_bytes: 21076
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
	int n, q;
	while(1){
		cin >> n >> q;
		if(n == 0 && q == 0) break;
		map<string, pair<long long int, long long int> > era;
		string inputs[1000];
		long long int by, wy;
		for(int i = 0; i < n; i++){
			cin >> inputs[i] >> by >> wy;
			era[inputs[i]] = make_pair<long long int, long long int>(wy - (by - 1), wy);
		}
		long long int query;
		for(int i = 0; i < q; i++){
			cin >> query;
			for(int j = 0; j < n; j++){
				if(era[inputs[j]].first <= query && era[inputs[j]].second >= query){
					cout << inputs[j] << " " << query - era[inputs[j]].first + 1 << endl;
					break;
				} else if(j == n - 1){
					cout << "Unknown" << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1352
N = int(input())
As = list(map(int, input().split()))

def func(Bs):
    for x in range(N):
        if Bs[x] >= 0: continue
        if max(Bs[x::x + 1]) <= 0:
            Bs[x] = 0

func(As)

zs = [27, 29, 31, 33] + list(range(34, 51))
for x in zs:
    if sum(As[x - 1::x]) < 0:
        for i in range(x - 1, N, x):
            As[i] = 0

ns = [1, 2, 4, 8, 16, 32] + [3, 6, 9, 12, 18, 24, 27, 36, 48] \
    + [5, 10, 15, 20, 25, 30, 40, 45, 50] + [7, 14, 21, 28, 35, 42, 49] \
    + [11, 22, 33, 44] + [13, 26, 39] + [17, 34] + [19, 38] + [23, 46] \
    + [29, 31, 37, 41, 43, 47]

memo = {}
memo[tuple(As)] = sum(As)

cs = [n - 1 for n in ns if n <= N and n not in zs and As[n - 1] < 0]
for c in cs:
    for tupleA in list(memo.keys()):
        if tupleA[c] == 0:
            continue

        listA = list(tupleA)
        for x in range(c, N, c + 1):
            listA[x] = 0

        func(listA)
        memo[tuple(listA)] = sum(listA)

print(max(memo.values()))


Measured memory_bytes: 4980
/*
[abc128] B - Guidebook
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100;

int N;
string S[MAX_N];
int P[MAX_N];
vector<pair<pair<string, int>, int>> ls;

void solve() {
    for (int i = 0; i < N; i++) {
        ls.push_back({{S[i], -P[i]}, i + 1});
    }
    sort(ls.begin(), ls.end());
    for (int i = 0; i < N; i++) {
        cout << ls[i].second << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> P[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 256
MOD = 998244353 #有名素数
fact = [0] * 220000
invfact = [0] * 220000

fact[0] = 1
for i in range(1, 220000):
    fact[i] = fact[i-1] * i % MOD

invfact[220000 - 1] = pow(fact[220000 - 1], MOD-2, MOD) #フェルマーの小定理より逆元を求める

for i in range(220000 - 2, -1, -1):
    invfact[i] = invfact[i+1] * (i+1) % MOD

def nCk(n, k):
    if k < 0 or n < k:return 0
    return fact[n] * invfact[k] * invfact[n-k] % MOD

n, m, k = map(int, input().split())
ans = 0

for i in range(0, k+1):
    ans += m * pow(m-1, n-i-1, MOD) * nCk(n-1, i) % MOD
    
print(ans % MOD)

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll m = X / gcd(X, 360LL) * 360LL;
    cout << m / X << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char a = sc.next().charAt(0);
		System.out.println(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o' ? "vowel" : "consonant");
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int a, b, c;

	cin >> a >> b >> c;


	if ((c >= a && c <= b) || (c >= b && c <= a)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}












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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	string s;
	int k;
	cin >> k >> s;
	
	if((int)s.size() > k) {
		s = s.substr(0,k);
		s += "...";
	}
	cout << s << endl;
  
	return 0;
}













Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

template<int mod=1000000007>
class ModInt {
  int x;
public:
  ModInt() : x(0) {}
  ModInt(const ModInt &y): x(y.x) {}
  ModInt(int64_t y){ x = y % mod; if(x < 0) x += mod; }
  ModInt &operator += (const ModInt &p){ x += p.x; if(x >= mod) x -= mod; return *this; }
  ModInt &operator -= (const ModInt &p){ x -= p.x; if(x < 0) x += mod; return *this; }
  ModInt &operator *= (const ModInt &p){ x = (int) (1LL * x * p.x % mod); return *this; }
  ModInt &operator /= (const ModInt &p){ *this *= p.inverse(); return *this; }
  ModInt operator -() const { return ModInt(-x); }
  ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
  ModInt operator ^ (const int64_t y) const { return pow(y); }
  bool operator == (const ModInt &p) const { return x == p.x; }
  bool operator != (const ModInt &p) const { return x != p.x; }
  ModInt operator = (const int64_t y) { return *this = ModInt(y); }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0){
      t = a/b; a -= t*b; swap(a, b);
      u -= t*v; swap(u, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t y) const {
    if(x==0) return ModInt(0);
    int64_t r = 1, t = x;
    while(y > 0){
      if(y&1) r = r*t%mod;
      t = t*t%mod; y >>= 1;
    }
    return ModInt(r);
  }
  friend ostream &operator << (ostream &os, const ModInt<mod> &p) { return os<<p.x; }
  friend istream &operator >> (istream &is, ModInt<mod> &a) { int64_t x; is>>x; a = ModInt<mod>(x); return is; }
};
using Int = ModInt<>;

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

  vector<Int> fact(n+100);
  fact[0] = 1;
  rep(i,1,n+100) fact[i] = fact[i-1] * i;

  Int ans = 1;
  for(long x = 2; x <= m; x++){
    int cnt = 0;
    while(m%x == 0){
      cnt++;
      m /= x;
    }
    if(cnt > 0){
      ans *= fact[n-1 + cnt] / fact[n-1] / fact[cnt];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
# coding: utf-8
def main():
    N,Q = map(int, input().split())
    s = input()
    ans = N
    command = []

    # print(char_list)

    for i in range(Q):
        t,d = input().split()
        command.append([t,d])

    r = binary_serch_R(command,s,N)
    #print(r)
    l = binary_serch_L(command,s,N)
    #print(l)
    ans = ans - (N-r) - (l+1)
    if ans < 0:
        ans = 0
    print(ans)

def simulation_R(command,s,now,N):
    for pair in command:
        if pair[0] == s[now]:
            if pair[1] == 'L':
                now -= 1
            elif pair[1] == 'R':
                now += 1
        if now < 0:
            return False
        elif now >= N:
            return True
    return False

def simulation_L(command,s,now,N):
    for pair in command:
        if pair[0] == s[now]:
            if pair[1] == 'L':
                now -= 1
            elif pair[1] == 'R':
                now += 1
        if now < 0:
            return True
        elif now >= N:
            return False
    return False


def binary_serch_R(command,s,N):
    left = 0
    right = N-1
    if simulation_R(command,s,left,N) :
        return -1
    if simulation_R(command,s,right,N) == False:
        return N

    while abs(right - left) > 1:
        mid = int((left+right)/2)
        # print(mid)
        if simulation_R(command,s,mid,N) :
            right = mid
        else :
            left = mid 
    return right

def binary_serch_L(command,s,N):
    left = 0
    right = N-1
    if simulation_L(command,s,left,N) == False :
        return -1
    if simulation_L(command,s,right,N):
        return N
        
    while abs(right-left) > 1:
        mid = int((left+right)/2)
        if simulation_L(command,s,mid,N) :
            left = mid
        else :
            right = mid 
    return left

if __name__ == "__main__":
    main()

Measured memory_bytes: 23732
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int arr[3][3];
	for(int i=0;i<3;i++)
  {
		for(int j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	int n;
	cin>>n;
	int tmp[n];
	for(int i=0;i<n;i++)
	  cin>>tmp[i];
	int ans=0;
	int count1=0,count2=0,count3=0,count4=0;
	for(int i=0;i<3;i++)
	{
    
		for(int j=0;j<n;j++)
		{
      if(arr[i][0]==tmp[j]||arr[i][1]==tmp[j]||arr[i][2]==tmp[j])
			  count1++;
		}
		for(int j=0;j<n;j++)
		{
      if(arr[0][i]==tmp[j]||arr[1][i]==tmp[j]||arr[2][i]==tmp[j])
			  count2++;
		}
		for(int j=0;j<n;j++)
		{
      if(arr[i][i]==tmp[j])
			  count3++;
		}
		for(int j=0;j<n;j++)
		{
      if(arr[i][2-i]==tmp[j])
			  count4++;
		}

		if(count1==3||count2==3||count3==3||count4==3)
	  {
			 cout<<"Yes";
		   return 0;
		}
		count1=0;
		count2=0;
	}
		cout<<"No";
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}




int main() {
	Int N; cin >> N;
	if (N % 2 == 0) cout << N << endl;
	else cout << 2 * N << endl;


	return 0;
}

Measured memory_bytes: 256
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
	fast;
	ll t = 1;
	cin >> t;
	vector<ll> v1,v2;
	for(ll i=0;i<t;i++)
	{
		ll x,y;
		cin>>x>>y;
		v1.push_back(x+y);
		v2.push_back(x-y);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	ll ans1 = abs(v1[0] - v1[t-1]);
	ll ans2 = abs(v2[0] - v2[t-1]);
	cout<<max(ans1,ans2);
	return 0;
}


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

int main(void){
    // Your code here!
    long long N;
    cin>>N;
    for(long long i=1;i<=N;i++){
        long long X=i*1.08;
        if(X==N){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
    return 0;
}



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

void reader(int *x) {
	int k = getchar(); *x = k - '0';
	while (true) {
		k = getchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];

void bfs(int u) {
	queue<int>que;
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int v : E[p]) {
			if (d[v] == d[p] + 1 && !ok[v]) {
				ok[v] = true; cnt++; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	queue<int>que;
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int i : E[p]) {
			if (d[i] == -1) {
				d[i] = d[p] + 1; que.push(i);
			}
		}
	}
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = true;
	}
	ok[0] = true;
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] - d[u[i]] == 1) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = true;
				bfs(v[r[i]]);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 13716
N, M = map(int, input().split())

AC = [0] * 200000
WA = [0] * 200000

for _ in range(M):
	P, S = map(str, input().split())
	p = int(P)
	if S == 'AC':
		AC[p] = 1
	else:
		if AC[p] == 0:
			WA[p] += 1

ac = 0
wa = 0
for i in range(N):
	if AC[i+1] == 1:
		ac += 1
		wa += WA[i+1]

print(ac, wa)

Measured memory_bytes: 48344
//retest
import java.io.PrintWriter

fun main(args: Array<String>) = Thread(null, ::abc138d_test, "", 64 * 1024 * 1024).start()

@OptIn(ExperimentalStdlibApi::class)
fun abc138d_test() {

    val pw = PrintWriter(System.out)

    val (n, q) = readLine()!!.split(' ').map { it.toInt() }

    val paths = Array(n) { ArrayDeque<Int>() }
    val values = IntArray(n) { 0 }

    repeat(n - 1) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        paths[line[0] - 1].add(line[1] - 1)
        paths[line[1] - 1].add(line[0] - 1)
    }

    repeat(q) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        values[line[0] - 1] += line[1]
    }
    val visited = BooleanArray(n) { false }

    fun dfs(i: Int) {
        visited[i] = true

        repeat(paths[i].size) {
            val index = paths[i].removeFirst()
            if (!visited[index]) {
                values[index] += values[i]
                dfs(index)
            }
        }
    }

    dfs(0)

    pw.print(values[0])
    values.drop(1).forEach {
        pw.print(" $it")
    }

    pw.println()
    pw.flush()
}


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

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


int main(){
  ll n;
  cin >> n;
  vector<ll> ans(4,0);
  rep(i,n){
    string s;
    cin >> s;
    if(s=="AC"){
      ans[0]++;
    }else if(s=="WA"){
      ans[1]++;
    }else if(s=="TLE"){
      ans[2]++;
    }else{
      ans[3]++;
    }
  }

  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;

  return 0;
} 



Measured memory_bytes: 3628
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]

l = [False for _ in range(N + 1)]
def solve():
    ans = 0
    l[0] = True
    for i in range(N + 1):
        if l[i] and i + 4 < N + 1:
            l[i + 4] = True
    for i in range(N + 1):
        if l[i] and i + 7 < N + 1:
            l[i + 7] = True
    return l[N]

if __name__ == "__main__":
    if solve():
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3768
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200010
#define MO 1000000007
struct node
{
	int v,x,id;
}e[MAXN];
bool cmp1(node a,node b)
{
	return a.v<b.v;
}
bool cmp2(node a,node b)
{
	return a.x<b.x;
}
int n,mx,l[MAXN],r[MAXN],dp[MAXN],sum[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&e[i].x,&e[i].v);
	sort(e+1,e+1+n,cmp1);
	for(int i=1;i<=n;i++)
		e[i].id=i;
	sort(e+1,e+1+n,cmp2);
	int mx=0,mn=n+1;
	for(int i=1;i<=n;i++)
	{
		mx=max(mx,e[i].id);
		r[i]=mx;
	}
	for(int i=n;i;i--)
	{
		mn=min(mn,e[i].id);
		l[i]=mn;
	}
	sum[0]=1;
	for(int i=1,j=1;i<=n;i++)
	{
		for(;j<=r[i];j++) sum[j]=sum[j-1];
		dp[i]=((sum[r[i]]-(l[i]==1?0:sum[l[i]-2]))%MO+MO)%MO;
		(sum[r[i]]+=dp[i])%=MO;
	}
	int ans=((sum[n]-sum[n-1])%MO+MO)%MO;
	printf("%d\n",ans);
}


Measured memory_bytes: 5632