akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	VV<int> G(N);
	rep(i,N-1){
		int x,y;
		cin >> x >> y;
		G[x].pb(y);
		G[y].pb(x);
	}
	V<int> c(N);
	function<void(int,int)> dfs = [&](int v,int p){
		for(int u: G[v]) if(u != p){
			if(G[u].size() == 2){
				dfs(u,v);
			}else{
				c[u]++;
			}
		}
	};
	rep(i,N) if(G[i].size() == 1){
		dfs(i,-1);
	}
	int ans = 0;
	rep(i,N) if(c[i]) ans += c[i]-1;
	chmax(ans,1);
	cout << ans << endl;
}


Measured memory_bytes: 12416
S=input()

odd=['R','U','D']
even=['L','U','D']
flag=True
for i in range(len(S)):
    if (i+1)%2==0 and not(S[i] in even):
        flag=False
        print('No')
        break 
    elif (i+1)%2==1 and not(S[i] in odd):
        flag=False
        print('No')
        break

if flag:
    print('Yes')


Measured memory_bytes: 3060
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextInt();
        long B = sc.nextInt();
        long C = sc.nextInt();
        long D = sc.nextInt();
        long ancs[] = new long[4];
    
        ancs[0] = A*C;
        ancs[1] = A*D;
        ancs[2] = B*C;
        ancs[3] = B*D;

        long max = ancs[0];
        for(int i = 0;i < 4;i++){
            if(max < ancs[i]){
                max = ancs[i];
            }
        }
        
        System.out.println(max);
    }
}

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

namespace Diverta
{
    class D
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            List<long> list = GetAllDivisors(N);

            long sum = 0;
            foreach(long x in list)
            {
                long k = x - 1;
                long a = N / x;
                if (a >= k) continue;
                sum += k;
            }
            Console.WriteLine(sum);
        }

        //全ての約数リストO(√n)
        public static List<long> GetAllDivisors(long x)
        {
            long sx = (long)Math.Sqrt(x);
            List<long> list = new List<long>();
            for (int n = 1; n <= sx; n++)
            {
                if (x % n == 0)
                {
                    long m = x / n;
                    list.Add(n);
                    if (n != m) list.Add(m);
                }
            }
            list.Sort();
            return list;
        }


    }
}


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


xor = [0]*(N+1)
cum = [0]*(N+1)
for i in range(N):
    xor[i] = xor[i-1]^A[i]
    cum[i] = cum[i-1]+A[i]

rlist = []
r = 0
for l in range(N):
    r = max(l+1,r)
    while r < N and xor[r]^xor[l-1] == cum[r]-cum[l-1]:
        r += 1
    if r == N:
        break
    r -= 1
    rlist.append(r)
ans = 0
rlist += [N-1]*(N-len(rlist))
for l in range(N):
    r = rlist[l]
    ans += r-l+1
print(ans)

Measured memory_bytes: 37084
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int a,b,c;

int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}

int main(){
  cin>>a>>b>>c;
  if(c%gcd(a,b)) puts("NO");
  else puts("YES");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define MAXN 1000002
using namespace std;
int prime[MAXN];
bool is_prime[MAXN];
int sum_prime[MAXN];
int sieve(int n){
  int p=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return p;

}
int main(void){
  int i;
  int a,d,n;
  sieve(MAXN);
  while(scanf("%d %d %d",&a,&d,&n),a|d|n){
    i=0;
    while(a>prime[i])i++;
    while(n){
      if(((prime[i]-a)%d)==0) n--;
      i++;
    }
    printf("%d\n",prime[i-1]);
  }
  return 0;
}

Measured memory_bytes: 4432
#include <stdio.h>
#include <string.h>
int main(void){
  char s[10];
  int l,f,i,a,b;
  scanf("%s",s);
  l=strlen(s);
  f=0;
  if(s[0]=='A')f++;
  a=0;
  for(i=2;i<l-1;i++){
    if(s[i]=='C')a++;
  }
  if(a==1)f++;
  for(i=0;i<l;i++){
    if(((s[i]>='a')&&(s[i]<='z'))||(s[i]=='A')||(s[i]=='C')) b++;
  }
  if(b==l)f++;
  if(f==3)printf("AC");
  else printf("WA");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

    int x = 10*(s[0] - '0') + (s[1] - '0');
    int y = 10*(s[2] - '0') + (s[3] - '0');

    if(x <= 12 && y <= 12 && x > 0 && y > 0) cout << "AMBIGUOUS" << endl;
    else if(x <= 12 && x > 0) cout << "MMYY" << endl;
    else if(y <= 12 && y > 0) cout << "YYMM" << endl;
    else cout << "NA" << endl;

    return 0;
}


Measured memory_bytes: 256
using namespace std;
//#include <bits/stdint.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    if(k<=a) cout << k << endl;
    else if(k>a&&k<=(a+b)) cout << a << endl;
    else cout << a-(k-a-b) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=55;
typedef long long ll;
typedef pair<int,int> P;
int n,a,x[N];
ll dp[N][3000];
int main()
{
    scanf("%d%d",&n,&a);
    for(int i=1;i<=n;i++) scanf("%d",&x[i]);
    dp[0][0]=1;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=x[i];
        for(int j=i;j>=1;j--)
            for(int k=sum;k>=x[i];k--)
            dp[j][k]+=dp[j-1][k-x[i]];
    }
    ll ans=0;
    for(int i=1;i<=n;i++) ans+=dp[i][i*a];
    cout<<ans<<endl;
    return 0;
}
 

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

int64_t intceil(int64_t a, int64_t b){
    if(a >= 0){
        return (a+b-1)/b;
    }else{
        return a/b;
    }
}
int64_t intfloor(int64_t a, int64_t b){
    if(a < 0){
        return (a-b+1)/b;
    }else{
        return a/b;
    }
}

int main(){
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    const int64_t INF = 1e18;
    int64_t ok = INF, ng = -INF-1;
    while(ok-ng>1){
        int64_t m = (ok+ng)/2;
        int64_t num = 0;
        for(int i=0; i<N; i++){
            if(A[i] < 0){
                int64_t v = intceil(-m, -A[i]);
                num += A.begin()+i - lower_bound(A.begin(), A.begin()+i, v);
            }else if(A[i] == 0){
                if(m >= 0) num += i;
            }else{
                int64_t v = intfloor(m, A[i]);
                num += upper_bound(A.begin(), A.begin()+i, v) - A.begin();
            }
        }
        (num >= K ? ok : ng) = m;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <cstring>

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 3000+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll a[N], dp[N][N];

ll f(int l, int r, bool maxi) {
    if (l > r) return 0;
    if (dp[l][r] != -1) return dp[l][r];
    ll L = f(l + 1, r, !maxi);
    ll R = f(l, r - 1, !maxi);
    if (maxi)
        return dp[l][r] = max(a[l] + L, a[r] + R);
    else
        return dp[l][r] = min(L - a[l], R - a[r]);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    rep (i, 0, n) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    cout << f(0, n-1, true) << endl;
    return 0;
}

Measured memory_bytes: 71040
inputs = gets.to_s.split(" ")

process_number = inputs[0].to_i
q_time = inputs[1].to_i
process_time = 0
i = 0
process = []
process_finish = []
for j in 0..process_number-1 do 
  process[j] = gets.to_s.split(" ")
end

while process.length != 0
  process_start = process[0][1].to_i - q_time

  if process_start > 0
    process[0][1] = process_start
    process.push(process[0])
    process.shift
    process_time += q_time
  end

  if process_start < 0
    process_time += (process[0][1].to_i)
    process[0][1] = process_time
    process_finish << process[0]
    process.shift
  end

  if process_start == 0
    process_time += q_time
    process[0][1] = process_time
    process_finish << process[0]
    process.shift
  end
end

for k in 0..process_number-1 do 
  puts process_finish[k].join(" ").strip
end



Measured memory_bytes: 15800
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi A(n);
  vi cnt(n);
  for(auto &a:A)cin>>a;
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++)
      if(A[i]>A[j])ans++;
  }
  ans*=k;
  ans%=MOD;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)
      if(A[i]>A[j])
	cnt[i]++;
  }
  for(int i=0;i<n;i++){
    ans+=(((k-1)*k/2)%MOD*(cnt[i]))%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

#define ll long long

int main() {
  int R, G, B, N;
  int ans = 0;
  cin >> R >> G >> B >> N;
  for (int r = 0; r <= N / R; r++) {
    for (int g = 0; g <= (N - r * R) / G; g++) {
      if ((N - r * R - g * G) % B == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,M;
  int ans = 0;
  cin >> N;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==N){
        ans = 1;
      }
    
  } }   
      if(ans>=1){
      cout << "Yes";
      }else{
      cout << "No";
      }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  bool a = false;
  bool b = false;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == 'A') {
      a = true;
    } else {
      b = true;
    }
  }
  if (a && b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong[] Tile = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray();
            if ((Tile[0] == 1) && (Tile[1] == 1)) Console.WriteLine("1");
            else if (Tile[0] == 1) Console.WriteLine($"{Tile[1] - 2}");
            else if (Tile[1] == 1) Console.WriteLine($"{Tile[0] - 2}");
            else Console.WriteLine($"{(Tile[0]-2) * (Tile[1]-2)}");

            Console.ReadKey();
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    string s;cin >>s;
    ll ans=0;
    ll l=0,r=0;//l:cnt black r:cnt white
    for (int i = 0; i < n; ++i) {
        if(s[i]=='.')r++;
    }
    ans=r;
    for (int i = 0; i <n; ++i) {
        if(s[i]=='#')l++;
        else {
            r--;
        }
        ans=min(ans,l+r);
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int cnt=1e7+7; 
int main(){
    int k;
    cin>>k;
    bool flag=0;
    ll sum=0;
    int ans;
	for(int i=0;i<cnt;i++){
		sum=(sum*10+7)%k;
		if(sum%k==0){
			flag=1;
			ans=i+1;
			break;
		}
	} 
	if(flag) cout<<ans;
    else cout<<"-1";
    
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

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

	int j=n/2;
	for(int i=1; i<=n; i++){
		b[j]=a[i-1];
		j+=i*pow(-1, i);
	}
	if(n%2==0){
		for(int i=0; i<n; i++){
			cout << b[i] <<" ";
		}
	} else {
		for(int i=n-1; 0<=i; i--){
			cout << b[i] <<" ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;


int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        if (s.back()=='s') {
            cout << s << "es" << endl;
        } else {
            cout << s << "s" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3612
import sys
import math
import fractions
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


# Nの素因数分解を辞書で返す
def prime_fact(n):
    if n == 1:
        return {1: 1}

    prime_dict = {}
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
        if n == 1:
            break
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def main():
    N = NI()
    A = NLI()

    if max(A) == 1:
        print("pairwise coprime")
        exit()

    g = A[0]
    for a in A:
        g = math.gcd(g, a)
    if g > 1:
        print("not coprime")
        exit()

    SA = set(A)
    if len(SA) >= 90000:
        print("setwise coprime")
        exit()

    p_cnt = defaultdict(int)
    cnt = 0
    for a in A:
        if a == 1:
            continue
        AP = prime_fact(a)
        for apk in AP.keys():
            p_cnt[apk] += 1

    max_p = max(p_cnt.values())
    if max_p == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")


if __name__ == "__main__":
    main()


Measured memory_bytes: 240140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll k;
  string s;
  cin >> k >> s;
  if(k>=s.size()){
    cout << s << endl;
  }
  else{
    string t="";
    rep(i,k){
      t+=s[i];
    }
    cout << t << "..." << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC";
    } else {
        cout << "ABC";
    }
    cout << '\n';

    fflush(stdout);
    return 0;
}


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

int main()
{
    vector<vector<int> > arr(4, vector<int>(13));
    char Z;
    int  I;
    int  N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
		cin >> Z >> I;
		if (Z == 'S')
          arr.at(0).at(I - 1) = 1;
     	else if (Z == 'H')
          arr.at(1).at(I - 1) = 1;
     	else if (Z == 'C')
          arr.at(2).at(I - 1) = 1;
      	else if (Z == 'D')
          arr.at(3).at(I - 1) = 1;
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (i == 0 && arr.at(i).at(j) != 1)
            {
                cout << 'S' << " " << j + 1 << endl;
                continue;
            }
            else if (i == 1 && arr.at(i).at(j) != 1)
            {
                cout << 'H' << " " << j + 1  << endl;
                continue;
            }
            else if (i == 2 && arr.at(i).at(j) != 1)
            {
                cout << 'C' << " " << j + 1 << endl;
                continue;
            }
            else if (i == 3 && arr.at(i).at(j) != 1)
            {
                cout << 'D' << " " << j + 1 << endl;
                continue;
            }
            else
                continue;
        }
    }
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n;
int a[N];
int p[N];
bool c[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else   
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        p[a[i]] = i;
    }   
    for (int i = 1; i < n; ++i) {
        c[i] = p[i] < p[i + 1];
    }   
    int ans = 0;
    int cur = 0;
    for (int i = 1; i < n; ++i) {
        if (c[i]) {
            ++cur;
        }
        else {
            ans = max(ans, cur);
            cur = 0;
        }   
    }   
    ans = max(ans, cur);
    cout << n - ans - 1 << '\n';
}   

Measured memory_bytes: 2048
#include<stdio.h>
#include<string.h>
int main(){
char s[4];
scanf("%s",&s);
//int len = strlen(s);
int i=0;
while(i!=3){
if(s[i]==s[i+1])
	{	 printf("Bad");
		break;
	}
i++;
}
if(i==3)
	printf("Good");



return 0;
}


Measured memory_bytes: 128
import java.util.Arrays; 
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void subsump(String in, Set<String> set){
		if(set.contains(in)){
			return;
		}
		
		//setの中に含まれている
		for(Iterator<String> iter = set.iterator(); iter.hasNext(); ){
			String set_str = iter.next();
			
			final int diff_len = set_str.length() - in.length();
			if(diff_len % 2 != 0){
				System.err.println("violate");
				return;
			}else if(diff_len >= 0){
				final int offset = diff_len / 2;
				if(set_str.startsWith(in, offset)){
					return;
				}
			}
		}
		
		//setの中に含まれている
		for(Iterator<String> iter = set.iterator(); iter.hasNext(); ){
			String set_str = iter.next();
			
			final int diff_len = in.length() - set_str.length();
			if(diff_len % 2 != 0){
				System.err.println("violate");
				return;
			}else if(diff_len >= 0){
				final int offset = diff_len / 2;
				if(in.startsWith(set_str, offset)){
					iter.remove();
				}
			}
		}
		
		set.add(in);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Set<String> odd  = new HashSet<String>();
		Set<String> even = new HashSet<String>();
		
		while(sc.hasNextLine()){
			String input = sc.nextLine().replaceAll("[^a-zA-Z]", "").toUpperCase();
			odd.clear();
			even.clear();
			
			final int length = input.length();
			
			for(int center = 1; center < length - 1; center++){
				{
					int low = center, high = center;
					
					while(true){
						if(low == 0 || high == length - 1){
							break;
						}else if(input.charAt(low - 1) != input.charAt(high + 1)){
							break;
						}
						
						low--;
						high++;						
					}
					
					if(low != high){
						subsump(input.substring(low, high + 1), odd);
					}
				}
				
				{
					int low = center, high = center - 1;
					
					while(true){
						if(low == 0 || high == length - 1){
							break;
						}else if(input.charAt(low - 1) != input.charAt(high + 1)){
							break;
						}
						
						low--;
						high++;						
					}
					
					if(high - low > 2){
						subsump(input.substring(low, high + 1), even);
					}
				}
			}
			
			boolean first = true;
			for(String str : odd){
				if(first){
					first = false;
					System.out.print(str);
				}else{
					System.out.print(" " + str);
				}
			}
			for(String str : even){
				if(first){
					first = false;
					System.out.print(str);
				}else{
					System.out.print(" " + str);
				}
			}
			System.out.println();
		}
		
		sc.close();
	}
}

Measured memory_bytes: 20224
#include <stdio.h>
int main(void){
    int n, a[100000+5];
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", &a[i]);
    
    int ans=0;
    for(int i=0; i<n; i++){
        ans++;
        while(a[i]==a[i+1])i++;
        if(a[i]<a[i+1])while(a[i]<=a[i+1])i++;
        else while(a[i]>=a[i+1])i++;
    }
    
    printf("%d\n", ans);
    return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    for(int i = 0; i < a; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < b; ++i){
        cin >> t[i];
    }
    while(q--){
        ll x;
        cin >> x;
        ll ans = LLINF;
        if(s[0] <= x && t[0] <= x) ans = min(ans, x - min(*(upper_bound(begin(s), end(s), x) - 1), *(upper_bound(begin(t), end(t), x) - 1)));
        if(s[0] <= x && x <= t[b-1]) ans = min(ans, *upper_bound(begin(t), end(t), x) - *(upper_bound(begin(s), end(s), x) - 1) + min(x - *(upper_bound(begin(s), end(s), x) - 1), *upper_bound(begin(t), end(t), x) - x));
        if(x <= s[a-1] && x <= t[b-1]) ans = min(ans, max(*(lower_bound(begin(s), end(s), x)), *(lower_bound(begin(t), end(t), x))) - x);
        if(t[0] <= x && x <= s[a-1]) ans = min(ans, *upper_bound(begin(s), end(s), x) - *(upper_bound(begin(t), end(t), x) - 1) + min(x - *(upper_bound(begin(t), end(t), x) - 1), *upper_bound(begin(s), end(s), x) - x));
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 2944
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 10000000;

ll res(ll a){
    return a+(a*a)+(a*a*a);
}
int main(){
        _
        ll n; cin >> n; cout<<res(n)<<endl;
return 0;
}



Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 300;
const int K = 100000;
const int mod = 1e9 + 7;
pair <int, pair<int,int>> op(pair <int, pair<int,int>> x, pair <int, pair<int,int>> y){
    return {x.F + y.F + y.S.F * x.S.S, {x.S.F + y.S.F, x.S.S + y.S.S}};
}
pair <int, pair<int,int>> e(){
    return {0, {0, 0}};
}
pair <int, pair<int,int>> mapping (int f, pair <int, pair<int,int>> x){
    if (f == 0) return x; else return {x.S.F * x.S.S - x.F, {x.S.S, x.S.F}};
}
int  composition (int f, int g){
    return f ^ g;
}
int id (){
    return 0;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, q;
    cin >> n >> q;
    vector <pair <int, pair<int,int>>> v(n);
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        v[i] = {0, {(x == 0), (x == 1)}};
    }
    lazy_segtree<pair <int, pair<int,int>>, op, e, int, mapping, composition, id> lst(v);
    while(q--){
        int t;
        cin >> t;
        if (t == 1){
            int l, r;
            cin >> l >> r;;
            lst.apply(l - 1, r, 1);
        } else{
            int l, r;
            cin >> l >> r;
            cout << lst.prod(l - 1, r).F << endl;
        }
    }
}


Measured memory_bytes: 22232
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
int main() {
int N, C; 
cin >> N >> C; 
int D[35][35] = {0}, c[510][510] = {0}; 
for (int i = 1; i <= C; i++){
 for (int j = 1; j <= C; j++){
cin >> D[i][j]; 
}
}
for (int i = 0; i < N; i++){
 for (int j = 0; j < N; j++){
cin >> c[i][j]; 
}
}
int X[35][5] = {0}; 
for (int i = 1; i <= C; i++){
for (int k = 0; k < N; k++){
 for (int l = 0; l < N; l++){
  if((k + l) % 3 == 0) X[i][0] += D[c[k][l]][i]; 
  else if((k + l) % 3 == 1) X[i][1] += D[c[k][l]][i]; 
  else if((k + l) % 3 == 2) X[i][2] += D[c[k][l]][i]; 
}
}
}
int ans = 1000000000; 
for (int i = 1; i <= C; i++){
 for (int j = 1; j <= C; j++){
for (int k = 1; k <= C; k++){
  if(j != i && k != j && k != i){
  int Y = X[i][0] + X[j][1] + X[k][2]; 
  ans = min(ans, Y); 
}
}
}
}
cout << ans << endl; 
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
const ll N = 1e5 + 1;
ll dp[N];
void solve(){
  ll n;
  cin >> n;
  ll a[n + 1];
  foa(i, 1, n+1){
    cin >> a[i];
  }
  dp[1] = 0;
  dp[2] = abs(a[1]-  a[2]);
  for(ll i = 3; i <= n; i++){
    dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i-2]));
  }
  cout << dp[n] << nl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 5360
# ABC142D - Disjoint Set of Common Divisors
def gcd(x: int, y: int) -> int:
    while y:
        x, y = y, x % y
    return x


def prime_factors(x: int) -> list:
    if x % 2:
        max_prime, factors = 0, []
    else:
        max_prime, factors = 2, [2]
        while x % 2 == 0:
            x //= 2
    for i in range(3, int(x ** 0.5) + 1, 2):
        if x % i == 0:
            max_prime = i
            factors.append(i)
            while x % i == 0:
                x //= i
    if x > 2:  # when x is prime greater than 2
        factors.append(x)
    return factors


def main():
    # compute the number of prime factors of gcd(A, B)
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factors(g)) + 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
S = list(input())
N = len(S)

for i in range(10):
  S.append('')

judge = 1
s1,s2,prev_s1 = '','',''
i = 0
while(1):
 s1 = S[i]+S[i+1]+S[i+2]+S[i+3]+S[i+4]
 s2 = S[i]+S[i+1]
 s2_ = list(s2)
 if(s1 == ''):
  break
 if((s1 == 'erase')or(s1 == 'dream')): 
  i += 5
 elif(s2 == 'er'):
  if(prev_s1 == 'dream'):
    i += 2
  else: 
    judge = 0
    break
 elif(s2_[0] == 'r'):
  if(prev_s1 == 'erase'):
    i += 1
  else: 
    judge = 0
    break
 else:
    judge = 0
    break
 prev_s1 = s1

if(judge == 1):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3956
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  int n;
  int k;
  int[] p;
  int ans;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      n = sc.nextInt();
      k = sc.nextInt();
      p = new int[n];
      for (int i = 0; i < n; i++) p[i] = sc.nextInt();
    } finally {
      sc.close();
    }
  }
  
  void solve() {
    Arrays.sort(p);
    for (int i = 0; i < k; i++) ans += p[i];
  }

  void show() {
    System.out.println(ans);
  }
}


Measured memory_bytes: 38624
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], c[200005];
map<int, int> cnt1, cnt2;
bool cmp1(pair<int, int> a, pair<int, int> b){
    return a.second < b.second;
}
bool cmp2(pair<int, int> a, pair<int, int> b){
    return cnt1[a.first] < cnt1[b.first];
}
int n;
bool solve(vector<int> f, vector<pair<int, int> > x){
    bool ok = 1;
    for(int i=1;i<=n;i++){
        if(!x.empty()){
            if(x.back().first == a[i]){
                pair<int, int> temp = x.back();
                x.pop_back();
                if(!x.empty()){
                    x.back().second--;
                    c[i] = x.back().first;
                    if(x.back().second == 0) x.pop_back();
                }
                else{
                    if(f.empty()){
                        ok = 0;
                        break;
                    }
                    c[i] = f.back();
                    f.pop_back();
                }
                x.emplace_back(temp);
            }
            else{
                x.back().second--;
                c[i] = x.back().first;
                if(x.back().second == 0) x.pop_back();
            }
        }
        else{
            if(f.empty()){
                ok = 0;
                break;
            }
            c[i] = f.back();
            f.pop_back();
        }
    }
    return ok;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    srand(178);

    cin >> n;

    vector<int> v;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        cnt1[a[i]]++;
    }
    vector<int> f;
    vector<pair<int, int> > x;
    for(int i=1;i<=n;i++){
        cin >> b[i];
        cnt2[b[i]]++;
        if(!cnt1.count(b[i])) f.emplace_back(b[i]);
    }

    for(auto it:cnt2){
        if(cnt1.count(it.first)){
            x.emplace_back(make_pair(it.first, it.second));
        }
    }

    vector<int> f2 = f;
    vector<pair<int, int> > x2 = x;

    sort(x.begin(), x.end(), cmp1);
    bool ok = solve(f, x);
    if(!ok){
        f = f2;
        x = x2;
        ok = solve(f, x);
    }

    if(!ok){
        f = f2;
        x = x2;
        sort(x.begin(), x.end(), cmp2);
        ok = solve(f, x);
    }
    for(int j=0;j<50;j++){
        f = f2;
        x = x2;
        ok = 1;
        random_shuffle(x.begin(), x.end());
        ok = solve(f, x);

        if(ok) break;
    }
    if(ok){
        printf("Yes\n");
        for(int i=1;i<=n;i++) printf("%d ", c[i]);
        printf("\n");
    }
    else printf("No\n");
}

Measured memory_bytes: 28836
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,x,m,ans=0;
    cin>>n>>x>>m;
    int used[m]={};
    while(used[x]==0){
        used[x]=1;
        ans+=x;
        n--;
        if(n==0){
            cout<<ans<<endl;
            return 0;
        }
        x=x*x%m;
    }
    long long syuki=1,start=x;
    long long syuki_sum=x;
    x=x*x%m;
    while(x!=start){
        syuki_sum+=x;
        x=x*x%m;
        syuki++;
    }
    ans+=(n/syuki)*syuki_sum;
    n%=syuki;
    while(n){
        ans+=x;
        n--;
        x=x*x%m;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf (ll)2e18
#define EPS 1e-12
#define MOD (ll)(1e9 + 7)
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int s, w;
	cin >> s >> w;
	cout << ((s > w) ? "safe" : "unsafe");
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	fore(t, 0, q)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3644
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    s = list(input())
    ans = 0
    for i in range(1, n):
        if s[i] != s[i-1]:
            ans += 1
    print(ans+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_11_A
{
    public class Program

    {

        public class Dice
        {
            public int top;
            public int front;
            public int right;
            public int left;
            public int back;
            public int bottom;

            public Dice(int[] num)
            {
                this.top = num[0];
                this.front = num[1];
                this.right = num[2];
                this.left = num[3];
                this.back = num[4];
                this.bottom = num[5];
            }

            public void TurnU()
            {
                int tmp = this.top;
                this.top = this.front;
                this.front = this.bottom;
                this.bottom = this.back;
                this.back = tmp;
            }

            public void TurnR()
            {
                int tmp = this.right;
                this.right = this.top;
                this.top = this.left;
                this.left = this.bottom;
                this.bottom = tmp;
            }
        }


        public static void Main(string[] args)
        {
            int[] line = ReadIntAr();
            Dice dice = new Dice(line);
            string cmd = ReadSt();
            for (int i = 0 ; i < cmd.Length ; i++)
            {
                switch (cmd[i])
                {
                    case 'N':
                        dice.TurnU();
                        break;
                    case 'S':
                        dice.TurnU(); dice.TurnU(); dice.TurnU();
                        break;
                    case 'E':
                        dice.TurnR();
                        break;
                    case 'W':
                        dice.TurnR(); dice.TurnR(); dice.TurnR();
                        break;
                }
            }
                 Console.WriteLine(dice.top);
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  ll ans=1;
  while(n--) {
    ans=min(ans*2,ans+k);
  }
  cout << ans << endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    sort(a.begin(), a.end());
    long long ans = 0;
    if (n % 2 == 0) {
        vector<int> b{1, -1};
        int m = n / 2 - 1;
        for (int i = 0; i < m; i++) b.emplace_back(-2), b.emplace_back(2);
        sort(b.begin(), b.end());
        for (int i = 0; i < n; i++) ans += a[i] * b[i];
    } else {
        vector<int> b{1, 1};
        int m = n / 2;
        for (int i = 1; i < m; i++) b.emplace_back(2);
        for (int i = 0; i < m; i++) b.emplace_back(-2);
        for (int k: {1, -1}) {
            for (int &bi: b) bi *= k;
            sort(b.begin(), b.end());
            long long tmp = 0;
            for (int i = 0; i < n; i++) tmp += a[i] * b[i];
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

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 long long INF = 1LL << 60;

long long h[100010];
long long dp[100010];

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

	for(int i=0;i<N;i++) cin >> h[i];


	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	// 初期条件
	dp[0] = 0;

	// ループ
	for (int i = 0; i < N; ++i) {
		for(int j = 1; j < K+1; ++j){
    	chmin(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
		}
	}

	cout << dp[N-1] << endl;

	}


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

int main(){
    int a,b;
    cin >> a >> b;
    int sa = (a+11)%13;
    int sb = (b+11)%13;
    if(sa > sb){
        cout << "Alice";
    } else if(sa < sb){
        cout << "Bob";
    } else {
        cout << "Draw";
    }
}


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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 100000000
int n;

int main(){
    int a,b;
	cin >> a >> b;
	
	if(a > 9 || b > 9) cout << -1 << endl;
	else cout << a*b << endl;
    
    return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;


//ここから

void solve(){
  string s;
  cin>>s;
  string a=s.substr(0,2),b=s.substr(2,2);
  int x=stoi(a),y=stoi(b);
  bool nga=false,ngb=false;
  if(x>12||x==0)nga=true;
  if(y>12||y==0)ngb=true;
  if(nga&&ngb)cout<<"NA";
  else if(nga)cout<<"YYMM";
  else if(ngb)cout<<"MMYY";
  else cout<<"AMBIGUOUS";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
# dpE
import sys
input = sys.stdin.readline

def main():
    N, W = tuple(map(int, input().rstrip().split()))
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
    _, V = zip(*A)
    lim = 10 ** 5
    dp = [0] + [float("inf")] * lim
    for i in range(N):
        for j in range(lim, A[i][1] - 1, -1):
            dp[j] = min(dp[j], dp[j - A[i][1]] + A[i][0])
    ans = [i for i, j in enumerate(dp) if j <= W]
    print(max(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 72764
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    static public void Main()
    {
        var s = new Sol();
        s.Solve1();
        s.Solve2();
        s.Solve3();
    }
}
public class Sol
{
    //ARC076 C Dubious Document2
    //https://atcoder.jp/contests/abc076/tasks/abc076_c
    public void Solve1()
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        var L = new List<string>();
        //sの始点
        for(int i = 0; i <= s.Length - t.Length ; i++)
        {
            bool ok = true;
            //tと比較
            for(int j = 0; j < t.Length; j++)
            {
                if (s[i+j] == '?') continue;
                if (s[i+j] == t[j]) continue;
                ok = false;
            }
            if (ok)
            {
                string ans = "";
                for(int j = 0; j < i; j++)
                {
                    if (s[j] == '?') ans += 'a';
                    else ans += s[j];
                }
                ans += t;
                for(int j = i + t.Length; j < s.Length; j++)
                {
                    if (s[j] == '?') ans += 'a';
                    else ans += s[j];
                }
                L.Add(ans);
            }
        }
        if (L.Count > 0) Console.WriteLine(L[L.Count - 1]);
        else Console.WriteLine("UNRESTORABLE");
    }

    //
    //
    public void Solve2()
    {

    }

    //
    //
    public void Solve3()
    {

    }
}

Measured memory_bytes: 26144
#include <iostream>
#include<vector>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < c &&c<b ){
		cout << "Yes" << endl;
	}
	else if (b < c&&c < a){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    for(int i=N;i>=1;i--){
        int x=sqrt(i);
        if(x*x==i){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H,W;
  cin >> H >>W;
  vector<string> IN(H);
  int i;
  for(i=0;i<W+2;i++){
    if(i<=W){
      cout <<"#";
    }else{
      cout <<"#" <<endl;
          }  
  }
  
  for(i=0;i<H;i++){
  
    cin >>IN.at(i);
    cout <<"#"<<IN.at(i)<<"#" <<endl;
  }
  
   for(i=0;i<W+2;i++){
    if(i<=W){
      cout <<"#";
     }else{
      cout <<"#" <<endl;
          }  
  }
 
}



Measured memory_bytes: 256