akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int E(int a) {
	return (5 * a + 17) % 32;
}

int D(int a) {
	return (13 * (a - 17 + 32)) % 32;
}

void Cout(vector<int> A) {
	for (auto x : A) {
		char c = x + 'a';
		cout << c;
	}
	cout << endl;
}

int main() {
	int i, j, k;

	int N, M, K;
	int Q;

	int S;
	cin >> N >> K >> S;
	int other = S - 1;
	if (other == 0) {
		other = 100000;
	}
	rep(i, 0, K) {
		cout << S << " ";
	}
	rep(i, K, N) {
		cout << other << " ";
	}
	return 0;
}

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

void trace(int A[], int n) {
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

int main() {
	int n; cin >> n;
	int A[110];

	for (int i = 0; i < n; i++) cin >> A[i];

	trace(A, n);
	for (int i = 1; i < n; i++) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, n);
	}

	return 0;
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

int main(){
  int w,h,n;
  int x,y,a;

  scanf("%d %d %d",&w,&h,&n);

  int wl = 0;
  int hu = 0;
  REP (i, n) {
    scanf("%d %d %d",&x,&y,&a);
    if (a == 1 && wl < x) wl = x;
    else if (a == 2 && w > x) w = x;
    else if (a == 3 && hu < y) hu = y;
    else if (a == 4 && h > y) h = y;
  }

  if (wl <= w && hu <= h) printf("%d\n",abs(w - wl) * abs(h - hu));
  else printf("0\n");
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	if (a*b%2==0) {
    		System.out.println("Even");
    	} else {
    		System.out.println("Odd");
    	}
 
    }
}

Measured memory_bytes: 21076
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c ] <- readInts
	putStrLn $ which "YES" "NO" $ any ( ( == c ) . ( `mod` b ) ) $ take 100 $ [ a, 2 * a .. ]


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;
int fact[N],inv[N];


int ncr(int n,int r)
{
    return  ( ( (fact[n]*inv[n-r])%mod ) * inv[r] )%mod;
}

int distanceBetweenPoint(array<int,2> p,array<int,2> q)
{
    if(p[0]<=q[0]&&p[1]<=q[1])
    {
        int down=q[1]-p[1];
        int right=q[0]-p[0];
        return ncr(down+right,down);
    }
    return 0;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 
 fact[0]=1;
 inv[0]=1;
 for(int i=1;i<N;i++)
 {
    fact[i]=(fact[i-1]*i)%mod;
    inv[i]=fp(fact[i],mod-2);
 }


 int n,H,W;
 cin>>H>>W>>n;
 vector<array<int,2>> obs(n);
 for(int i=0;i<n;i++)
 {
    cin>>obs[i][0]>>obs[i][1];
 }
 sort(obs.begin(),obs.end(),[&](array<int,2> p,array<int,2> q){
    return p[0]+p[1]<q[0]+q[1];
 });

 int ways=distanceBetweenPoint({1,1},{H,W});

 //cout<<ways;

 int w[n+1]; //no of ways to reach ith obstacle ,with passing no obstacle 1...i-1
 
 for(int i=0;i<obs.size();i++)
 {
    if(i==0)
    {
        w[i]=distanceBetweenPoint({1,1},obs[i]);
    }
    else
    {
        w[i]=distanceBetweenPoint({1,1},obs[i]);
        for(int j=0;j<i;j++)
        {
            w[i]-=(distanceBetweenPoint(obs[j],obs[i])*w[j])%mod;
            if(w[i]<0)
                w[i]+=mod;
        }
    }
    ways-=(w[i]*distanceBetweenPoint(obs[i],{H,W}))%mod;
    if(ways<0)
        ways+=mod;
 }

 cout<<ways;




}

Measured memory_bytes: 6844
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ab = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int aCount = 0;
        int bCount = 0;
        int abCount = 0;
        if(a + b <= ab * 2){
            aCount = x;
            bCount = y;
        }
        else{
            if(x > y){
                int k = x - y;
                abCount = y * 2;
                if(ab * 2 < a){
                    abCount += k * 2;
                }
                else aCount += k;
            }
            else{
                int k = y - x;
                abCount = x * 2;
                if(ab * 2 < b){
                    abCount += k * 2;
                }
                else bCount += k;
            }
        }
        System.out.println(aCount * a + bCount * b + ab * abCount);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
{
  ios_base::sync_with_stdio(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  multiset<int> red, green, both;
  FOR(i, 1, a)
    {
    int xx;
    cin >> xx;
    red.insert(xx);
    }
  FOR(i, 1, b)
    {
    int xx;
    cin >> xx;
    green.insert(xx);
    }
  FOR(i, 1, c)
    {
    int xx;
    cin >> xx;
    both.insert(xx);
    }
  debug(red, green, both);

  while(red.size() > x)red.erase(red.begin());
  while(green.size() > y)green.erase(green.begin());
  while(both.size() && (*(--both.end()) > *red.begin() || *(--both.end()) > *green.begin()))
    {
    int val = *(--both.end());
    both.erase(--both.end());
    if(*green.begin() > *red.begin())
      {
      red.erase(red.begin());
      red.insert(val);
      }
    else
      {
      green.erase(green.begin());
      green.insert(val);
      }
    }
  LL val = 0;
  debug(red, green);
  for(auto i: red)val += i;
  for(auto i: green)val += i;
  cout << val << endl;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;char st;
    cin>>n;
    string str;
    for(int i=0;i<=n;i++){
        while(getline(cin,str)){
        bool kawa=0;
        for(int j=1;j<50&&!kawa;j++){
            for(int k=1;k<50&&!kawa;k++){
                string strin=str;
                for(int l=0;strin[l]!='\0';l++)
                	if(strin[l]-'a'>=0&&strin[l]-'z'<=0)
                		strin[l]=(j*(strin[l]-'a')+k)%26+'a';
                for(int l=0;strin[l]!='\0';l++){
                    if(strin[l]=='t'&&strin[l+1]=='h'&&
                    		(strin[l+2]=='a'&&strin[l+3]=='t'||strin[l+2]=='i'&&strin[l+3]=='s')){
                    	cout<<strin<<endl;
                    	kawa=1;
                    	break;
                    }
                }
            }
        }
        }
    }
}

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

namespace ConsoleApp11
{
    class Class73
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Dictionary<int, int> D_Table = new Dictionary<int, int>();
            for(int i = 0; i < N; i++)
            {
                if (D_Table.ContainsKey(read[i])) D_Table[read[i]]++;
                else D_Table[read[i]] = 1;
            }
            int M = int.Parse(Console.ReadLine());
            var T_read = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Dictionary<int, int> T_Table = new Dictionary<int, int>();
            for(int i = 0; i < M; i++)
            {
                if (T_Table.ContainsKey(T_read[i])) T_Table[T_read[i]]++;
                else T_Table[T_read[i]] = 1;
            }

            bool frag = true;

            foreach(int i in T_Table.Keys)
            {
                if (D_Table.ContainsKey(i))
                {
                    if (D_Table[i] >= T_Table[i])
                        continue;
                    else { frag = false;break; }
                }
                else { frag = false;break; }
            }
            Console.WriteLine(frag ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 59652
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

int main(){
  int a, b, c;
  int k;
  cin >> a >> b >> c;
  cin >> k;


  int _max = max(a, max(b, c));
  cout << (_max * pow(2, k)) + ((a+b+c) - _max) << endl;

  return 0;
}

Measured memory_bytes: 256
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let s = read_line().split("").map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();
	let mut c = 0;
	for i in s.iter() {
		if i == "o" {
			c+=1;
		}
	}
	println!("{}",700+(100*c));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using ps = pair<string,string>;

ps split(string s){
    int n = s.size();
    int idx = 0;
    while(idx<n && s[idx]!='-') ++idx;

    return {s.substr(0,idx), s.substr(idx+1)};
}

const int N = 202;
const int INF = 101010;

// 入力から分かる強さ関係
vector<int> G[N];
bool arr[N][N];

int d[N][N];

// 水準関係
int C[N][N];

int main(){
    int n;
    while(cin >>n,n){
        rep(i,N) G[i].clear();
        rep(i,N)rep(j,N) arr[i][j] = false;

        rep(i,N)rep(j,N) d[i][j]=INF;
        rep(i,N) d[i][i]=0;

        rep(i,N)rep(j,N) C[i][j]=INF;
        rep(i,N) C[i][i]=0;

        map<string,int> c2id;
        int V = 0;
        vector<string> names;
        rep(i,n){
            string s;
            cin >>s;
            ps cross = split(s);

            if(!c2id.count(cross.fi)){
                c2id[cross.fi] = V;
                ++V;
                names.pb(cross.fi);
            }
            if(!c2id.count(cross.se)){
                c2id[cross.se] = V;
                ++V;
                names.pb(cross.se);
            }
            int u = c2id[cross.fi], v = c2id[cross.se];
            G[u].pb(v);
            C[u][v] = 1;
            d[u][v] = d[v][u] = 1;
            arr[u][v] = true;
        }

        rep(k,V)rep(i,V)rep(j,V) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

        auto same_degree = [&](int a, int b){
            bool same = false;
            rep(i,V){
                if( (arr[a][i]||arr[i][a]) && (arr[b][i]||arr[i][b]) ) same = true;
            }
            if(!same) return false;

            rep(i,V){
                if(arr[i][a]&&arr[b][i]) return false;
                if(arr[a][i]&&arr[i][b]) return false;
            }
            return true;
        };

        rep(i,V)rep(j,i){
            if(same_degree(i,j)){
                // cout << "DEG :: " << names[i] << " " << names[j] << endl;
                C[i][j] = C[j][i] = 1;
            }
        }
        rep(k,V)rep(i,V)rep(j,V) C[i][j] = min(C[i][j], C[i][k]+C[k][j]);

        cout << V << endl;

        int Q;
        cin >>Q;
        while(Q--){
            string q;
            cin >>q;

            ps qc = split(q);

            bool ok = false;
            if(c2id.count(qc.fi) && c2id.count(qc.se)){
                int u = c2id[qc.fi], v = c2id[qc.se];
                // dbg(C[u][v]);

                if(d[u][v]%2==1 && C[u][v]<INF) ok = true;
            }
            cout << (ok?"YES":"NO") << endl;
        }
        // dbg(c2id.size());
        // dbg(names);
    }
    return 0;
}



Measured memory_bytes: 3416
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll N,M,K;
ll table[10];
bool check[10];

int main(){

	scanf("%lld %lld %lld",&N,&M,&K);

	ll ans = 0;

	if(M == 0){

		printf("%lld\n",K*(N%10));
		return 0;
	}

	if((N%10) == 0){

		printf("0\n");
		return 0;

	}else if((N%10) == 1){

		printf("%lld\n",K);
		return 0;
	}

	ll index = 0;
	table[index++] = (N%10);

	ll current = (N%10),cycle;
	for(int i = 0; i <= 9; i++){
		check[i] = false;
	}

	check[current] = true;

	//周期と、現れる数を調べる
	while(true){

		current = current*(N%10);
		current %= 10;

		if(check[current]){

			cycle = index;
			break;
		}
		check[current] = true;
		table[index++] = current;
	}

	//K個の数列を、サイクルの余り別に調べる
	ll diff = M%cycle;
	ll num_cycle = K/cycle; //サイクルの数

	ll pos = 0;

	for(int i = 0; i < cycle; i++){

		ans += num_cycle*table[pos];
		pos += diff;
		pos %= cycle;
	}


	if(num_cycle == 0){

		pos = 0;

		for(int i = 0; i < K; i++){

			ans += table[pos];
			pos += diff;
			pos %= cycle;
		}

	}else{

		pos = 0;

		for(int i = 0; i < K%(cycle*num_cycle); i++){

			ans += table[pos];
			pos += diff;
			pos %= cycle;
		}
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3232
//  Created by conan1024hao on 2019/11/19.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;
    cin>>n;
    vector<double>x(n);
    vector<string>v(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>v[i];
    }
    double ans=0;
    for(int i=0;i<n;i++){
        if(v[i]=="JPY")
            ans+=x[i];
        else
            ans+=x[i]*380000;
    }
    printf("%.5lf\n",ans);
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

using namespace std;

typedef long long ll;

// 二部グラフ判定
int max_N = 100005;

vector<int> colors(max_N, -1);
vector<vector<int>> g(max_N, vector<int>());

bool dfs(int v, int color){
	colors[v] = color;

	for(int x : g[v]){
		if(colors[x] == color) return false;
		if(colors[x] == -1 && !dfs(x, 1 - color)) return false;
	}

	return true;
}

bool is_bipartite(){
	return dfs(0, 1);
}

const int INF = 1e9;

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

	int n;
	cin >> n;

	string strg[n];
	rep(i, n) cin >> strg[i];

	rep(i, n) rep(j, n){
		if(strg[i][j] == '1' ){
			g[i].push_back(j);
			g[j].push_back(i);
		}
	}

	if(!is_bipartite()){
		cout <<  -1 << endl;
	}else{

		vector<vector<int>> dist(n, vector<int>(n, INF));
		rep(i, n) rep(j, n){
			if(strg[i][j] == '1') dist[i][j] = 1;
		}

		rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

		int d = 0;
		rep(i, n) rep(j, n){
			if(i == j) continue;
			d = max(d, dist[i][j]);
		}

		cout << d + 1 << endl;
	}



}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;

  int sub = abs(a-b);
  ll i = 0;
  while (i * 2LL <= n - 1LL) {
    ll ma = d * (n - 1LL - i * 2LL);
    ll mi = c * (n - 1LL - i * 2LL);

    ll mma = abs(c-d) * i;
    if (mi - mma <= sub and sub <= ma + mma) {
      cout << "YES" << endl;
      return 0;
    }
    i++;
  }
  cout << "NO" << endl;
}


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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++) a[i] = sc.nextInt();
        Arrays.sort(a);
        boolean[] A = new boolean[a[n-1]+1];
        int count = 0;
        for(int i = 0;i<n;i++){
            if(!A[a[i]]){
                if(!(i+1<n&&a[i+1]==a[i]))count++;
                for(int j = a[i];j<=a[n-1];j+=a[i])A[j]=true;
            }
        }
        System.out.println(count);
	}
}


Measured memory_bytes: 60756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
vi dy = { 0,0,1,-1 };
vi dx = { 1,-1,0,0 };
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;


int main() {

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

	bool can = true;

	vi mna(n,0), mxa(n,0);
	int mn = 1;


	rep(i, n - 1) mxa[i + 1] = a[i] + 1;

	ll ans = 0;

	rep(i, n) {
		mn--;
		if (a[n - 1 - i] < mn || mxa[n - i - 1] < a[n - 1 - i]) {
			can = false;break;
		}

		if (a[n - 1 - i] == mn)continue;

		ans += a[n - 1 - i];
		mn = a[n - 1 - i];
	}

	if (can)cout << ans << endl;
	else cout << -1 << endl;

}

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

int main()
{
  int n;
  cin >> n ;
  for (int i =0; i < n; i++){
    string b;
    cin >> b;
    if(b == "Y"){
      cout << "Four" << endl;
      break;
    }
    if (i == n-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			string s = cin.Next();
			int n = s.Length;
			int ans = 0;
			int temp = 0;
			for (int i = 0; i < n; i++) {
				if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
					++temp;
				} else {
					ans = Math.Max(ans, temp);
					temp = 0;
				}
			}

			ans = Math.Max(ans, temp);

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13140
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=0,A=0,B=0,BA=0;
  cin>>n;
  vector<string> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n){
    if(v[i][0]=='B' && v[i][v[i].size()-1]=='A') BA++;
    else if(v[i][v[i].size()-1]=='A') A++;
    else if(v[i][0]=='B') B++;
    rep(j,v[i].size()){
      if(v[i].substr(j,2)=="AB") ans++;
    }
  }
  if(BA==0){
    cout<<ans+min(A,B)<<endl;
  }else{
    if(A+B==0) cout<<ans+BA-1<<endl;
    else cout<<ans+BA+min(A,B)<<endl;
  }
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    String s = sc.next();

    if (s.length() > k) {
      System.out.println(s.substring(0,k) + "...");
    } else {
      System.out.println(s);
    }
  }
}

Measured memory_bytes: 38692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][][] list = new int[4][3][10];
        for (int i = 0; i < n; i++) {
            String[] lines = br.readLine().split(" ");
            int[] nList = new int[4];
            for (int j = 0; j < 4; j++) {
                nList[j] = Integer.parseInt(lines[j]) - 1;
            }
            list[nList[0]][nList[1]][nList[2]] += nList[3] + 1;
        }
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 3; k++) {
                for (int l = 0; l < 10; l++) {
                    if (0 != list[j][k][l]) {
                        System.out.print(" " + list[j][k][l]);
                    } else {
                        System.out.print(" 0");
                    }
                }
                System.out.println();
            }
            if (j != 3) {
                System.out.println("####################");
            }
        }
    }
}

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

int main(){
    using namespace std;
    string s;
    cin >> s;
    int i = 0;
    for (int j = 0; j < s.size(); j++){
        if(s.at(j)=='+')
            i++;
        else
        {
            i--;
        }
        
    }
    cout <<i<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe


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

int n,a;
double b;

cin >> b;

n = b;

a = b/2;

if (n%2 == 0)
{
    cout << 0.5 << endl;
}else
{
    cout << (a+1)/b << endl;
}







//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, K;
	cin >> N >> K;
	priority_queue<int>q;
	int num;
	rep(i, N) {
		cin >> num;
		q.push(num);
	}
	int sum = 0;
	rep(i, K) {
		sum += q.top();
		q.pop();
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int n,u,v,dep,dv;
VI e[N];

void dfs(int u,int f,int d) {
	if (d>dep) {
		dep=d;
		dv=u;
	}
	for (auto v:e[u]) if (v!=f) {
		dfs(v,u,d+1);
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	dep=-1; dv=-1;
	dfs(1,0,0);
	int du=dv;
	dep=-1; dv=-1;
	dfs(du,0,0);
	if (dep%3==1) {
		puts("Second");
	} else {
		puts("First");
	}
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int32_t main()
{
	IOS;
	int a, b;
	cin>>a>>b;
	if(a<=0 && b>=0)
		cout<<"Zero";
	else
	{
		int neg=max(0LL, -a) - max(0LL, -(b+1));
		if(neg%2)
			cout<<"Negative";
		else
			cout<<"Positive";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1; char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e5+20;

int n,m;
vector<int>ed[maxn];
char str[maxn];

int rda[maxn],rdb[maxn];

inline void init()
{
	n=read();m=read();
	scanf("%s",str+1);
	REP(i,1,m)
	{
		int x=read(),y=read();
		ed[x].push_back(y);
		ed[y].push_back(x);
		(str[y]=='A'?rda:rdb)[x]++;
		(str[x]=='A'?rda:rdb)[y]++;
	}
}

int num,vis[maxn];

inline void doing()
{
	queue<int>q;
	REP(i,1,n)if(!rda[i] || !rdb[i])q.push(i);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		if(vis[u])continue; num++;vis[u]=1;
		for(int v:ed[u])
		{
			if(!--(str[u]=='A'?rda:rdb)[v])
				q.push(v);
		}
	}
	if(num==n)puts("No");
	else puts("Yes");
}

int main()
{
	init();
	doing();
	return 0;
}



Measured memory_bytes: 13184
s=input()
t=input()
ls=len(s);lt=len(t)
ans=10000
for i in range(ls-lt+1):##
    ss=list(s[i:i+lt])
    tt=list(t)
    
    tmp=[tt[j] for j in range(lt) if tt[j]!=ss[j]]
    ans=min(ans,len(tmp))
print(ans)

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

int main(void){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i{0}; i<N; ++i){
        cin >> d[i];
    }
    int sum{0};
    for(int i{0}; i<N-1; ++i){
        for(int j{i+1}; j<N; ++j){
            sum+= d[i]*d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
// #ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
       *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
// #else
// sim dor(const c&) { ris; }
// #endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int maxn=2e5+5,INF=1e9+5;
int tree[4*maxn],lazy[4*maxn];
const long long INFL=1e18+5ll;

void push(int node,int lo,int hi){
    if(lazy[node]==0){
        return;
    }
    int mid=(lo+hi)/2;
    tree[node<<1]=tree[node];
    lazy[node<<1]=lazy[node];
    tree[node<<1 | 1]=lazy[node]+mid+1-lo;
    lazy[node<<1 | 1]=tree[node<<1 | 1];
    lazy[node]=0;
}

void upd(int node,int lo,int hi,int l,int r,int v){
    if(lo>hi || lo>r || hi<l){
        return;
    }
    if(lo>=l && hi<=r){
        lazy[node]=v+lo-l;
        tree[node]=v+lo-l;
        return;
    }
    push(node,lo,hi);
    int mid=(lo+hi)/2;
    upd(node<<1,lo,mid,l,r,v);
    upd(node<<1 | 1,mid+1,hi,l,r,v);
    tree[node]=min(tree[node<<1],tree[node<<1 | 1]);
}

int query(int node,int lo,int hi,int l,int r){
    if(lo>hi || lo>r || hi<l){
        return INF;
    }
    if(lo>=l && hi<=r){
        return tree[node];
    }
    push(node,lo,hi);
    int mid=(lo+hi)/2;
    return min(query(node<<1,lo,mid,l,r),query(node<<1 | 1,mid+1,hi,l,r));
}

void solve(){
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        int a,b;
        cin>>a>>b;
        --a,--b;
        int st=INF;
        if(a>0){
            st=query(1,0,w-1,a-1,a-1);
        }
        // debug()<< imie(st);
        upd(1,0,w-1,a,b,st+1);
        // debug()<< imie(tree[1]);
        if(tree[1]<INF){
            cout<<tree[1]+i+1<<'\n';
        }
        else{
            cout<<-1<<'\n';
        }
        // for(int i=0;i<w;i++){
        //     debug()<< imie(query(1,0,w-1,i,i));
        // }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int ara[102];
    for(int i=0;i<102;i++)
        ara[i]=0;
    int ans=0;
    for(int i=0;i<n;i++){
        int m;
        cin>>m;
        ara[m]++;
    }
    for(int i=0;i<102;i++){
        if(ara[i]>0)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
void solve()
{
	int n;
	cin>>n;
	vector<int> vect(n);
	REP(i,n)
	{
		cin>>vect[i];
	}
	int start = 1;
	bool pos = 0;
	int cnt = 0;
	REP(i,n)
	{
		if(vect[i]==start)
		{
			pos = 1;
			start++;
			cnt++;
		}
	}
	if(!pos)
	{
		cout<<"-1\n";
		return;
	}
	else
	{
		cout<<n-cnt<<"\n";
	}
}
int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
const ll INF = 1e15;

vector<int> z_algorithm(const string &s) {
  vector<int> prefix(s.size());
  for (int i = 1, j = 0; i < s.size(); i++) {
    if (i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while (i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int)s.size();
  return prefix;
}

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

  ll ans = 0;
  REP(i, n) {
    auto x = z_algorithm(s.substr(i, n));
    REP(j, n - i) {
      if (x[j] > j) continue;
      ans = max(ans, (ll)x[j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
"14:05分開始"

S = str(input())

ans = 1

now = S[0]  # 最初は一文字目を取り出せばよい
pointa = 1
while True:
    if pointa >= len(S):
        break
    if len(now) == 2:
        now = S[pointa]  # 一文字取り出せば良い
        pointa += 1
        ans += 1
        continue
    # 今nowは一文字
    if now != S[pointa]:  # 文字が違うのであれば一文字取り出せばよい
        ans += 1
        now = S[pointa]
        pointa += 1
    elif now == S[pointa]:  # nowと今見ている文字が等しいなら二文字取り出すしかない
        if pointa >= len(S)-1:
            break
        now = S[pointa] + S[pointa+1]
        pointa += 2
        ans += 1

print(ans)

Measured memory_bytes: 3500
import java.util.*;

public class Main {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] frags = new int[n];
		int i = 0;
		while(sc.hasNext()) {
			frags[i++] = sc.nextInt();
		}
		Main soln = new Main();
		System.out.println(soln.jdg(t, frags));
	}

	private long jdg(int t, int[] frags) {
		long res = (long)t;
		if(frags.length==1) return res;
		int dlt = 0;
		for(int i=0; i<frags.length-1; i++) {
			dlt = frags[i+1]-frags[i];
			res += (long)((dlt<t)? dlt:t);
		}
		return res;
	}
}

Measured memory_bytes: 75580
n,k = map(int,input().split())
count = 0
def sai(a,b):
    p = 0
    while a < b:
        a = a*2
        p = p + 1
    return p
for i in range(n):
    count = count + float((1/n)*(1/(2**(sai(i+1,k)))))
print(count)

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  for (int i{}; i < N; ++i) {
    cin >> x[i];
  }
  for (int i{}; i < M; ++i) {
    cin >> y[i];
  }
  sort(x, x + N);
  sort(y, y + M);

  bool ans = x[N-1] < y[0] && X < x[N-1] && y[0] <= Y;

  cout << (ans ? "No War" : "War") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    char s[5000];
    long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(i=1;i<=n;i++)
    {
        if(s[i]=='R')
        {
            r++;
            red[i]=red[i-1]+1;
            blue[i]=blue[i-1];
            green[i]=green[i-1];
        }
        else if(s[i]=='G')
        {
            g++;
            green[i]=green[i-1]+1;
            red[i]=red[i-1];
            blue[i]=blue[i-1];
        }
        else if(s[i]=='B')
        {
            b++;
            blue[i]=blue[i-1]+1;
            red[i]=red[i-1];
            green[i]=green[i-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {          
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
            {
                x=b-blue[j];
                y=(j-i)+j;
                if(s[y]=='B'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;
                }
            }
            else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
            {
                x=g-green[j];
                y=(j-i)+j;
                if(s[y]=='G'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;
                }
            }
            else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
            {
                x=r-red[j];
                y=(j-i)+j;
                if(s[y]=='R'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;
                }
            }
        }
    }
    cout<<total<<endl;
    return 0;
}

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

int main(){
	int n, k, x;
	int sum = 0;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> x;
		sum += 2 * min(x, k - x);
	}
	cout << sum;
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int A,B,C,D; cin >> A >> B >> C >> D;
    ll dp[C+1][D+1]; REP(i,C+1)REP(j,D+1) dp[i][j] = 0;

    dp[A][B] = 1;
    REP(i,C+1)REP(j,D+1){
        if(i) (dp[i][j] += dp[i-1][j] * j) %= MOD;
        if(j) (dp[i][j] += dp[i][j-1] * i) %= MOD;
        if(i && j){
            dp[i][j] -= (dp[i-1][j-1] * (i-1) * (j-1))%MOD;
            if(dp[i][j]<0) dp[i][j] += MOD;
        }
    }

    cout << dp[C][D] << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 73996
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,c,b,a;
    cin>>n>>m>>c;
    std::deque<int> deq;
    for (int i=0;i<m;i++) {
        cin>>b;
        deq.emplace_back(b);
    }
    int count=0;
    for (int j=0;j<n;j++) {
        int sum=0;
        for (int k=0;k<m;k++) {
            cin>>a;
            sum+=deq[k]*a;
        }
        sum+=c;
        if (sum>0) {
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define precise fixed<<setprecision(50)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll n, a[4] = {0};
double dp[301][301][301];
bool vis[301][301][301] = {0};
double calc(ll c1, ll c2, ll c3){
	if(c1 < 0 || c2 < 0 || c3 < 0)	return 0;
	if(c1+c2+c3 == 0)	return 0;
	if(vis[c1][c2][c3])	return dp[c1][c2][c3];
	vis[c1][c2][c3] = 1;
	double ans = c1*(1+calc(c1-1, c2, c3)) + c2*(1+calc(c1+1, c2-1, c3)) + c3*(1+calc(c1, c2+1, c3-1)) + (n-c1-c2-c3);
	ans /= (c1 + c2 + c3);
	return dp[c1][c2][c3] = ans;
}
int main(){
	init();
	cin>>n;	ll x;
	for(ll i = 0; i < n; i++){ cin>>x; a[x]++; }
	cout<<precise<<calc(a[1], a[2], a[3]);
}

Measured memory_bytes: 125648
#include<stdio.h>

long int min(long int a,long int b){
    if(a < b){
        return a;
    }else{
        return b;
    }
}

int main(void){
    long int n,i,ans;
    long int attack1; //同じ番号の街を守る力
    long int attack2; //隣の番号の街を守る力

    scanf("%d",&n);
    long int a[n+10],b[n+10];
    for(i=1; i <= n+1; i++){
        scanf("%ld",&a[i]);
    }
    for(i=1; i <= n; i++){
        scanf("%ld",&b[i]);
    }
    
    ans = 0;

    attack1 = min(a[1], b[1]);              //brave1-city1
    attack2 = min(a[2], b[1] - attack1);    //brave1-city2
    ans += (attack1 + attack2);

    for(i=2; i<=n; i++){

        attack1 = min(a[i] - attack2, b[i]); //前の勇者のattack2
        attack2 = min(a[i+1], b[i]- attack1);

        ans += (attack1 + attack2);
    }
    
    printf("%ld\n",ans);

    return 0;
}

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

using namespace std;

int main() {
  string str;
  cin >> str;
  int n = static_cast<int>(str.size());
  for (int i = 1; i < n; ++i) {
    int a = (n - i) / 2;
    int b = n - i - a;
    if (a != b)
      continue;
    string sa = str.substr(0, a);
    string sb = str.substr(a, b);
    if (sa != sb)
      continue;
    cout << n - i << endl;
    break;
  }
}


Measured memory_bytes: 3604