akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

int main() {
    ios::sync_with_stdio(false);
    Int h, w;
    cin >> h >> w;
    char field[501][501] = {}, red[501][501] = {}, blue[501][501] = {};
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cin >> field[i][j];
            red[i][j] = blue[i][j] = field[i][j];
        }
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            if (j == 0) {
                red[i][j] = '#';
            }
            else if (j == w - 1) {
                blue[i][j] = '#';
            } 
            else {
                if (i % 2 == 0) {
                    red[i][j] = '#';
                }
                else {
                    blue[i][j] = '#';
                }
            }
        }
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cout << red[i][j];
        }
        cout << endl;
    }
    cout << endl;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            cout << blue[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
    int x, a, b;
    scanf("%d%d%d", &x, &a, &b);

    if (a >= b) printf ("delicious\n");
    else if (b - a <= x) printf("safe\n");
    else printf ("dangerous\n");

    return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    string T; cin >> T;
    for(auto c : T) {
        if(c == '?') cout << 'D';
        else cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 3776
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
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<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    ll n;
    cin >> n;
    ll r = 0;
    vll a(n);
    rep(i, n) {
        cin >> a[i];
        if (i >= 2) {
            if ((a[i-1] < a[i] && a[i-1] > a[i-2]) || (a[i-1] > a[i] && a[i-1] < a[i-2])) {
                r ++;
            }
        }
    }
    
    mes(r);
    
    
    
    
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18

        signed main() {
 

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin>>n;
        vector<int> v(n);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>v[i];
            if(i%2==0 && v[i]%2==1)
                ans++;
        }
        cout<<ans;



        return 0;
    }


Measured memory_bytes: 3648
from collections import *
from itertools import *

N = int(input())

A = map(int, input().split())
SA = SB = 0
ABI = sorted(((b:=max(N-i, i-1)*a, SA:=SA+a, SB:=SB+b) and (a, b, i) for i, a in enumerate(A, 1)), reverse=True)

prev = {0:0}
prev_max = 0
for k, (a, b, i) in enumerate(ABI):
  curr = defaultdict(int)
  curr_max = 0
  for l, p in prev.items():
    r = k-l
    if p + SB - min(l,r)*SA < prev_max:
      continue
    curr[l] = max(curr[l], p+abs(N-i-r)*a)
    curr[l+1] = p+abs(i-l-1)*a
    curr_max = max(curr_max, curr[l], curr[l+1])
  SA -= a
  SB -= b
  prev = curr
  prev_max = curr_max

print(curr_max)


Measured memory_bytes: 9984
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int h = scan.nextInt();
		int n = scan.nextInt();
		
		for(int i = 0; i < n; i++){
			h -= scan.nextInt(); 
		}
		
		System.out.println(h <= 0 ? "Yes" : "No");
		
	}
}

Measured memory_bytes: 47912
#include <stdio.h>

int main()
{
  int W, H, x, y, r;

  scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

  if ((x - r) >= 0 && (y - r) >= 0 && (x + r) <= W && (y + r) <= H) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

int main()
{
    long n;
    long long d{-1};
    long long c{-1};
    cin >> n;
    for (long i = 0; i < n; i++)
    {
        long long first, second;
        cin >> first >> second;
        c += first * second;
        d += second;
    }
    cout << c / 9 + d << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
string s,a;
int count1=1,count2=0;
cin >>s;
a=s;
for(int i=0;i<s.size()-1;i++){
   if(i==0&&s[i]=='0')s[i]=1;
   else if(i==0&&s[i]=='1')s[i]=0;
    if(s[i+1]=='1'&&s[i]=='1'){
       s[i+1]='0';
       count1++;
   continue;
    }
      if(s[i+1]=='0'&&s[i]=='0'){
       s[i+1]='1';
       count1++;
   continue;
    }

}
for(int i=0;i<a.size()-1;i++){
   if(a[i+1]=='1'&&a[i]=='1'){
       a[i+1]='0';
       count2++;
   continue;
    }
      if(a[i+1]=='0'&&a[i]=='0'){
       a[i+1]='1';
       count2++;
   continue;
    }
}
cout <<min(count1,count2);
 }



Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String s = sc.next(); 
        int first = s.indexOf("A");
        int last = s.lastIndexOf("Z");
        
        System.out.println(last - first + 1);
    }
}


Measured memory_bytes: 27456
"""
桁DPを使う
dp[i][j][k] => 合計値のi桁目がjになるようなABの組み合わせの数。kは未満フラグ
jが1のとき、その桁ではAが1でBが0のパターンと、Aが0でBが1のパターンが考えられる。
したがってdp[i+1][1] += dp[i][j]*2という遷移となる。
jが0のとき、その桁では必ずAもBも0となる。
したがってdp[i+1][0] += dp[i][j]という遷移となる。
"""
mod = 10**9 +7
L = input()
N = len(L)
dp = [[[0]*(2) for _ in range(2)]for _ in range(N)]
dp[0][0][1] = 1
dp[0][1][0] = 2

for i in range(N-1):
    x = int(L[i+1])
    for j in range(2):
        for k in range(2):
            if k == 0:
                r = x+1
            else:
                r = 2
            for l in range(r):
                if k == 0 and l == x:
                    flag = 0
                else:
                    flag = 1
                if l == 0:
                    dp[i+1][l][flag] += dp[i][j][k]
                else:
                    dp[i+1][l][flag] += dp[i][j][k]*2
                dp[i+1][l][flag] %= mod
ans = sum(dp[-1][1])+sum(dp[-1][0])
print(ans%mod)

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

using namespace std;

int N, A, B;

struct TGrader{
  string s;
  TGrader() {
    #ifndef ngfam
      cin >> A >> B; N = A + B;
    #else
      s = "10001110001110011100101010111";
      for(int i = 0; i < s.size(); ++i) {
        N++;
        if(s[i] == '1') A++;
        else B++;
      }
    #endif
  }

  bool ask(int x, int y) {
    #ifndef ngfam
      cout << "? " << x << " " << y << endl;
      string w; cin >> w;
      return (w == "Y");
    #else
      if(s[x] == '1') return (s[y] == '1');
      return rand() % 2;
    #endif
  }

  void guess(string t) {
    #ifndef ngfam
      cout << "! " << t << endl;
    #else
      if(s == t) cout << "Correct!!!";
      else cout << "Wrong answer" << endl;
    #endif
  }
}Grader;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  if(B >= A) {
    cout << "Impossible" << endl;
    return 0;
  }

  deque<int> vec;

  for(int i = 0; i < N; ++i) {
    if(vec.empty()) {
      vec.push_back(i);
      continue;
    }
    if(Grader.ask(vec.back(), i)) {
      vec.push_back(i);
      continue;
    }
    else {
      vec.pop_back();
    }
  }

  string ans;
  for(int i = 0; i < N; ++i) {
    ans += char('0' + (Grader.ask(vec.back(), i)));
  }

  Grader.guess(ans);

  return 0;
}


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

int main() {
  int n, p; cin >> n >> p;
  vector<int> A(n);
  rep(i,n) cin >> A[i];

  int oddcnt = 0;
  rep(i,n) {
    if (A[i] % 2) oddcnt++;
  }

  if (oddcnt == 0) {
    if (p == 1) {
      cout << 0 << endl;
    } else {
      cout << (1LL<<n) << endl;
    }
  } else {
    cout << (1LL<<n-1) << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var X = NextInt();
		var Y = NextInt();
		var Z = NextInt();

		WriteLine((X - Z) / (Y + Z));
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 13268
n = int(input())
d = list(list(map(int,input().split())) for _ in range(n))
for i in range(n-2):
    if d[i][0]==d[i][1]:
        if d[i+1][0]==d[i+1][1]:
            if d[i+2][0]==d[i+2][1]:
                print("Yes")
                break
else:
    print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1'000'000'000;
vector<ll> neg, pos;
ll zero_cnt;
ll get_negative(ll num) {
    ll cnt = 0;
    for (auto &val: neg) {
        ll pr = num / val;
        if (pr * val >= num) ++pr;
        cnt += pos.end() - lower_bound(pos.begin(), pos.end(), pr);
    }
    return cnt;
}
ll get_positive(ll num) {
    ll cnt = (ll)pos.size() * (ll)neg.size() + zero_cnt * (pos.size() + neg.size()) + zero_cnt * (zero_cnt - 1) / 2;
    for (int i = 1; i < neg.size(); ++i) {
        ll pr = (num - neg[i] - 1) / neg[i];
        auto ptr = upper_bound(neg.begin(), neg.begin() + i, pr);
        cnt += neg.begin() + i - ptr;
    }
    for (int i = 1; i < pos.size(); ++i) {
        ll pr = (num + pos[i] - 1) / pos[i];
        auto ptr = lower_bound(pos.begin(), pos.begin() + i, pr);
        cnt += ptr - pos.begin();
    }
    return cnt;
}
inline ll get_count(ll num) {
    if (num == 0) return (ll)neg.size() * (ll)pos.size();
    else if (num < 0) return get_negative(num);
    return get_positive(num);
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        ll tmp; cin >> tmp;
        if (tmp < 0) neg.push_back(tmp);
        else if (tmp == 0) ++zero_cnt;
        else pos.push_back(tmp);
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    ll left = -(INF * INF), right = INF * INF;
    while (left <= right) {
        ll mid = (left + right) / 2;
        ll cnt = get_count(mid);
        //cout << "left = " << left << " right = " << right << " mid = " << mid << " cnt = " << cnt << '\n';
        if (mid == left || mid == right) break;
        else if (cnt >= k) right = mid;
        else left = mid; 
    }
    cout << (get_count(left) >= k? right: left) << '\n';
    return 0;
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		for(int i = 0,j=0;i<n;i++) {
			var e=sc.Ia;
			if(e[0]==e[1]){j++;}
			else{j=0;}
			if(j==3){
				Console.WriteLine("Yes");
				return;
			}
		}
		Console.WriteLine("No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27524
#include <iostream>
using namespace std;
int main(){
	int n,num,i,j;
	cin>>n;
	int card[4][13]={0};
	char ch;
	for(i=0;i<n;i++){
		cin>>ch>>num;
		switch(ch){
		case 'S':
			card[0][num-1]++;
			break;
		case 'H':
			card[1][num-1]++;
			break;
		case 'C':
			card[2][num-1]++;
			break;
		case 'D':
			card[3][num-1]++;
			break;
			
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(card[i][j]==0){
				switch(i){
				case 0:
					ch='S';
					break;
				case 1:
					ch='H';
					break;
				case 2:
					ch='C';
					break;
				case 3:
					ch='D';
					break;
				}
				cout<<ch<<' '<<j+1<<endl;
			
			}
		}
	}
	return 0;
	
}

Measured memory_bytes: 1160
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
    
p = list(map(int, input().split()))
 
for i in range(101):
    if not x-i in p:
        print(x-i)
        break
    if not x+i in p:
        print(x+i)
        break

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int mod = 1e9 + 7;
const int maxn = 1005;
int a[maxn][maxn], dp[maxn][maxn];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s;
    REP(i, n) {
        cin >> s;
        REP(j, m) a[i + 1][j + 1] = s[j] == '.';
    }
    dp[1][1] = 1;
    REPP(i, 1, n + 1) REPP(j, 1, m + 1) {
        if (i == 1 && j == 1) continue;
        if (a[i][j]) {
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


Measured memory_bytes: 8192
K = "keyence"

S = raw_input()
N = len(S)
M = N - 7

if M == 0:
    print "YES" if S == K else "NO"
    exit()

for i in xrange(N):
    S1 = S[:i]
    S2 = S[i+M:]
    T = S1 + S2
    if T == K:
        print "YES"
        exit()

print "NO"


Measured memory_bytes: 2568
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
double dp[100010];
int N,M;
double p;
int g[20][20];
#define eps 1e-6
bool jud[20];
void dfs(int n)
{
    jud[n]=true;
    for(int i=0;i<N;i++)
    {
        if(g[n][i]&&!jud[i])
        {
            dfs(i);
        }
    }
}
int main()
{
    int i,j,k;
    int n,m,t;
    int a,b,s;
    scanf("%d%d%lf",&N,&M,&p);
    for(i=0;i<M;i++)
    {
        scanf("%d%d",&a,&b);
        a--;b--;
        if(a==b)
        {
            i--;M--;
            continue;
        }
        g[a][b]=g[b][a]=1;
    }
    p/=100.0;
    if(p<eps)
    {
        dfs(0);
        for(i=0;i<N;i++) if(!jud[i]) break;
        if(i==N) printf("1.000000000000\n");
        else printf("0.000000000000\n");
        return 0;
    }

    if(p>1.0-eps)
    {
        if(N>1) printf("0.000000000000\n");
        else printf("1.000000000000\n");
        return 0;
    }

    for(i=0;i<N;i++) dp[(1<<i)]=1.0;
    double pp;
    for(n=1;n<(1<<N);n++)
    {
        //cout<<n<<endl;
        for(i=0;i<N;i++) if(n==(1<<i)) break;
        if(i<N) continue;
        for(a=0;a<N;a++) if(n&(1<<a)) break;
        for(b=0;b<N;b++) if((n&(1<<b))&&b!=a) break;
        for(m=n&(n-1);m;m=n&(m-1))
        {
            if(m&(1<<a)) continue;
            if(!(m&(1<<b))) continue;
            t=n&(~m);pp=1.0;
            for(i=0;i<N;i++)
                if(((1<<i)&m)&&g[a][i]) pp*=p;
            pp=1.0/pp-1.0;
            dp[n]+=dp[m]*dp[t]*pp;
            //cout<<n<<"  "<<m<<"   "<<dp[n]<<endl;
        }
        //cout<<n<<"  "<<dp[n]<<endl;
    }
    for(i=0;i<M;i++) dp[(1<<N)-1]*=p;
    printf("%.12f\n",dp[(1<<N)-1]);
    return 0;
}

Measured memory_bytes: 1364
#include<stdio.h>
#include<string.h>

int main() {
   char str[20], temp;
   int i, j = 0;

   gets(str);

   i = 0;
   j = strlen(str) - 1;

   while (i < j) {
      temp = str[i];
      str[i] = str[j];
      str[j] = temp;
      i++;
      j--;
   }

   printf("%s\n", str);
   return (0);
}

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

int main() {
	string s,t;
	cin>>s>>t;
	long int ans=0,i;
	for(i=0;i<s.length();i++)
	{
	    if(s[i]!=t[i])
	        ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3916
#include<cstdio>
#include<bits/stdc++.h>
#define fi first
#define sc second
#define pb push_back
#define mp make_pair
using namespace std;
 
typedef pair<int, int> pi;

int dp[2][105], arr[2][105];
int N;

int f(int r, int c) {
	if (r == 1 && c == N - 1) return arr[r][c];
	if (r < 0 || r == 2 || c < 0 ||c >= N) return (int) -1e5;
	if (dp[r][c] != -1) return dp[r][c];
	int ans = arr[r][c];
	ans = max(ans, arr[r][c] + f(r + 1, c));
	ans = max(ans, arr[r][c] + f(r, c + 1)); 
	return dp[r][c] = ans;
}

int main() {   
	memset(dp, -1, sizeof(dp));
cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			cin >> arr[i][j];
		}
	}
	int ans = f(0, 0);
	cout << ans ;
	return 0;
}

Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  vector<int> vec(N);
  REP(i, N) {
    cin >> vec[i];
  }
  int res = 0;
  while (true) {
    if (*max_element(vec.begin(), vec.end()) == 0) {
      cout << res << endl;
      return 0;
    }
    int i = 0;
    while(i < N && vec[i] == 0) {
      i++;
    }
    res++;
    while(i < N && vec[i] > 0) {
      vec[i]--;
      i++;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 100000000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll dist[51][25101];
ll cost[51][51];
ll add[51],lom[51];
ll n;
vedos adj[51];
void dj(ll s,ll t){

  s=min(s,(ll)(25000));
  for (ll i = 0; i < n; ++i)
  {
    for (ll j = 0; j <= 25000; ++j)
    {
      dist[i][j]=INF;
    }
  }
  dist[0][s]=0;
  priority_queue<pair<dos,ll>,vector<pair<dos,ll>>,greater<pair<dos,ll>>>q;
  q.push({{0,0},s});
  while(!q.empty()){
    auto u=q.top();
    q.pop();
    for(auto it:adj[u.first.second]){
      ll next=it.first;
      ll costi=it.second;
      if(u.second-costi>=0 && dist[next][u.second-costi]>u.first.first+cost[next][u.first.second]){
        dist[next][u.second-costi]=u.first.first+cost[next][u.first.second];
        q.push({{dist[next][u.second-costi],next},u.second-costi});
      }
    }
    if(add[u.first.second]+u.second<=25000 && dist[u.first.second][add[u.first.second]+u.second]>u.first.first+lom[u.first.second]){
      dist[u.first.second][add[u.first.second]+u.second]=u.first.first+lom[u.first.second];
      q.push({{dist[u.first.second][add[u.first.second]+u.second],u.first.second},add[u.first.second]+u.second});
    }
  }
  for (ll i = 1; i < n; ++i)
  {
    ll ans=INF;
    for (ll j = 0; j <= 25000; ++j)
    {
      ans=min(ans,dist[i][j]);
    }
    cout<<ans<<'\n';
  }
  return;
}
int main()
{
  flash;
  ll m,s;
  cin>>n>>m>>s;
  for (ll i = 0; i < m; ++i)
  {
    ll x,y,z,f;
    cin>>x>>y>>z>>f;
    x--,y--;
    cost[x][y]=f;
    cost[y][x]=f;
    adj[x].pb({y,z});
    adj[y].pb({x,z});
  }
  for (ll i = 0; i < n; ++i)
  {
    cin>>add[i]>>lom[i];
  }
  dj(s,0);
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 37692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }
    // 同じ集合に属しているか判定
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    // 集合のサイズを取得
    ll size(int x)
    {
        return cnt[find(x)];
    }
};

int main()
{
    ll n,m;
    cin >> n >> m;
    UnionFindTree utree(n+10);
    vector<int> a(m);
    vector<int> b(m);
    vector<ll> ans(m);
    int i = 0;
    for (i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
    }
    ans[m - 1] = n * (n - 1) / 2;
    for (i = m - 1; i > 0; i--)
    {
        if (utree.same(a[i], b[i]))
            ans[i - 1] = ans[i];
        else
        {
            ans[i - 1] = ans[i] - utree.size(a[i]) * utree.size(b[i]);
            utree.unite(a[i], b[i]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


int main(){
  string s;
  cin >> s;
  set<char> se;
  FOR(i,0,3)se.insert(s[i]);
  if(se.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())

v1, v2 = [], []
for _ in range(n):
    a, b = map(int, input().split())
    v1.append(a)
    v2.append(b)
v1.sort()
v2.sort()

if n & 1:
    m = n // 2
    print(v2[m] - v1[m] + 1)
else:
    m = n // 2
    print(v2[m-1]-v1[m-1] + v2[m]-v1[m] + 1)

Measured memory_bytes: 25408
#include<iostream>
#include<list>

using namespace std;

int main()
{
	int n;
	int ans = 0;
	list<int> a,c;
	int buf = -1;
	

	cin >> n;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;

		if (k == buf +1) {
			a.push_back(buf);
		}
		buf = k;
	}

	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		ans += b;
	}

	a.sort();
	for (int i = 1; i < n ; i++) {
		int c;
		cin >> c;
		if (a.front() == i){
			ans += c;
			a.pop_front();
	}
	}

	
	cout << ans;
}

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;
#define MODSIZE 1000000007

ll ten(ll a,ll b){
  ll res;

  if(a % b == 0) res = a/b;

  else res = a/b + 1;

  return res;
}

int main(){

  int n;
  int a[1007],b[1007];
  int i;
  ll A,B;
  ll t;

  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d %d", &a[i], &b[i]);
  }

  A = 1; B = 1;

  for(i = 0;i < n;i++){
    t = max(ten(A,a[i]),ten(B,b[i]));
    A = t*a[i];
    B = t*b[i];
  }

  printf("%lld\n", A + B);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b;
    cin>>a>>b;
    bool flag=false;
    if(a%3==0||b%3==0||(a+b)%3==0) flag=true;
    if(flag) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl; 
    return 0;
}

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



int main() {
	
	int n;
	long long a[100001];
	long long b[100001];
	int num = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		
	}
	for (int i = 0; i < n; i++) {
		if (a[i] >= 0) {
			b[i] = a[i];
		}
		else {
			num++;
			b[i] = -1 * a[i];
		}
	}
	
	
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += b[i];
	}
	if (num % 2 == 0) cout << sum;
	else {
		long long  min = 1000000001;

		for (int i = 0; i < n; i++) {
			if (b[i] < min) min = b[i];
		}
		sum = sum - 2 * min;
		cout << sum;
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

const int MaxN = 200000;
const int MaxM = MaxN / 2;
const int NLet = 26;

int n;
char s[MaxN + 2];

int sum[MaxM + 1][NLet];

int fail[MaxM + 1];

int cir_l = 0;

inline void build_fail()
{
	int k = 0;
	for (int i = 2; i <= n; ++i)
	{
		while (k && s[k + 1] != s[i])
			k = fail[k];
		fail[i] = (k += s[k + 1] == s[i]);
	}
}

s64 solve(s64 l, int c)
{
	s64 res = 0;
	while (l > n)
	{
		s64 nl = cir_l, nr = n;
		s64 sl = sum[cir_l][c], sr = sum[n][c];

		while (l >= nl + nr)
		{
			nr += nl, nl = nr - nl;
			sr += sl, sl = sr - sl;
		}

		l -= nr, res += sr;
	}

	return res + sum[l][c];
}

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1) / 2;
	s[n + 1] = '\0';

	for (int i = 1; i <= n; ++i)
	{
		for (int c = 0; c < NLet; ++c)
			sum[i][c] = sum[i - 1][c];
		++sum[i][s[i] - 'a'];
	}

	build_fail();

	cir_l = n - fail[n];

	s64 l, r;
	cin >> l >> r;

	for (int c = 0; c < NLet; ++c)
		cout << solve(r, c) - solve(l - 1, c) << ' ';
	cout << endl;

	return 0;
}

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

long long ans = 100000000000000;

void dfs(vector<vector<int>> &a,int x,vector<int> skill,int n,long long a_ans){
    int size = a.at(0).size() - 1;
    bool ok = true;
    int next;
    long long in_ans;

    for(int i = 0;i < size;i++){
        if(skill[i] < x)ok = false;
    }
    
    if(ok) ans = min(a_ans,ans);

    else if(n == a.size())return;

    else{
        vector<int> now_skill(a.at(n).size() - 1,0);
        for(int j = 1;j < a.at(n).size();j++){
            now_skill[j - 1] += skill[j - 1]+ a[n][j];
        }
        int next = n + 1;
        in_ans = a_ans + a[n][0];
        dfs(a,x,now_skill,next,in_ans);
        dfs(a,x,skill,next,a_ans);
    }
}

int main(){
    int n,m,x;

    cin >> n >> m >> x;
    vector<int> skill(m,0);
    vector<vector<int>> book(n,vector<int>(m + 1,0));

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m + 1;j++){
            cin >> book[i][j];
        }
    }
    dfs(book,x,skill,0,0);

    if(ans == 100000000000000) cout << -1 << endl;
    else cout << ans << endl; 
}

Measured memory_bytes: 3624
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 998244353;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

vector<int>G[200020];
int point[200020];

bool vis[200020];
void dfs(int n) {
	vis[n] = true;
	for (auto nex : G[n]) {
		if (vis[nex])continue;
		point[nex] += point[n];
		dfs(nex);
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, Q; cin >> N >> Q;
	REP(i, N - 1) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	REP(i, Q) {
		int p, x; cin >> p >> x;
		p--;
		point[p] += x;
	}
	dfs(0);
	REP(i, N) {
		pe(point[i]);
	}cout << endl;
}



Measured memory_bytes: 21376
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args){

		Scanner scn = new Scanner(System.in);
		
		int a = scn.nextInt();
		int b = scn.nextInt();
		int c = scn.nextInt();
		
		int tmp;
		if (a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
		if (b > c){
			tmp = b;
			b = c;
			c = tmp;
		}
		if (a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
		System.out.println(a + " " + b + " " + c);
	}
}

Measured memory_bytes: 26116
<?php

fscanf(STDIN,"%d %d",$N,$M);
$a_list = explode(" ",trim(fgets(STDIN)));


$sum = 0;

for($i=0;$i<$M;$i++){
  $sum += $a_list[$i];
}


if($N-$sum <0){
  echo "-1\n";
}else{
echo ($N-$sum)."\n";
}





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

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)
#define rep(i,x,N) for(int i=x;i<=N;i++)
#define revrep(i,x,N) for(int i=x;i>=N;i--)
#define ar array

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
using vvi=vector<vi>;
int ctoi(char c) {return c-'0';}
int slen(string s) {return s.length();}
int vsize(vi a) {return (int)a.size();}
int in() {int x;cin>>x;return x;}
void tf(bool ok) {cout<<(ok ? "YES" : "NO")<<endl;}

//https://dmoj.ca/problem/dpv

const int MAXN = 1e5 + 10;

vector<int> g[MAXN];
ll dp[MAXN],c[MAXN],ans[MAXN];
int N,M;

void dfs1(int e,int p){
	dp[e]=1;
	vi cdrn;
	for(int& u : g[e]){
    if(u!=p) {
      dfs1(u,e);
      dp[e]=(dp[e]*(dp[u]+1))%M;
      cdrn.pb(u);
    }
	}

	vll ps,ss;
	ll pref=1,suf=1;
	forn(i,vsize(cdrn)) {
    ps.pb(pref);
		pref=(pref*(dp[cdrn[i]]+1))%M;
	}
	revrep(i,vsize(cdrn)-1,0) {
    ss.pb(suf);
		suf=(suf*(dp[cdrn[i]]+1))%M;
	}
	reverse(all(ss));
	forn(i,vsize(cdrn)) {
		c[cdrn[i]]=(ps[i]*ss[i])%M;
	}
}

void dfs2(int e,int p){
	ans[e]=(dp[e]*c[e])%M;
	for(int& u: g[e]){
      if(u!=p) {
      c[u]=(c[u]*c[e]+1)%M;
      dfs2(u,e);
    }
	}
}

int main(){

cin>>N>>M;
forn(i,N-1) {
  int u,v;
  cin>>u>>v;
  g[u].pb(v);
  g[v].pb(u);
}

dfs1(1,-1);
c[1] = 1;
dfs2(1,-1);

for(int i=1;i<=N;i++)
  cout<<ans[i]<<endl;
return 0;
}

Measured memory_bytes: 24964
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		if (r < 1200) {
			System.out.println("ABC");
		} else if (r >= 1200 && r < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main()
{
	int S;
	int W;
	
	cin >> S >> W;
	
	if((S<W) || (S==W)){
		cout << "unsafe" <<  std::endl;
		
	}else{
		cout << "safe" <<  std::endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  int n,m;in(n,m);
  out(n*(n-1)/2+m*(m-1)/2);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    i64 A, B;
    read(A, B);

    reps(i, 0, 21000) {
        const i64 a = i64(i * 0.08);
        const i64 b = i64(i * 0.1);
        if (a == A && b == B) {
            print(i);
            return 0;
        }
    }

    print(-1);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int n;
  vector<int> ans;
  cin>>n;

  vector<int> prime;
  vector<bool> furui(55556, true);
  for (int i=2; i < int(sqrt(55556)); ++i) {
    if(furui[i]){
      for (int j=0;i*(j+2)< 55556; ++j) {
        furui[i*(j+2)] = false;
      }

    }
  }

  for (int i=2; i < 55556; ++i) {
    if(furui[i])
      prime.push_back(i);
  }
  // for(auto p :prime)
  //   cout<<p<<endl;


  for(int  i=0; ans.size()<n; ++i) {
    int c = prime[i];
    if(c%5==1)
      ans.push_back(c);
  }

  // int sum = accumulate(ans.begin(), ans.end(), 0);

  // if(sum%2==0)
  //   ans.push_back(2);
  // else
  //   ans.push_back(3);


  for(auto a:ans)
    cout<<a<<" ";
  cout<<endl;
  // if(n%2==0){
  //   int minamoto=3;
  //   while(int(ans.size())<n)  {
  //     if(minamoto)
  //     minamoto
  //   }
  // }
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <map>
#include <climits>

using namespace std;

int main(){
    int nCases;
    long long int min, max;
    
    min = INT_MAX;
    max = INT_MIN;
    
    scanf("%d", &nCases);
    
    while(nCases--){
    long long int tmp;
        scanf("%lld", &tmp );
        
        if(tmp > max){
            max = tmp;
        }
        if(tmp < min){
            min = tmp;
        }
    }
    
    printf("%lld\n", max - min);

    return 0;
}


Measured memory_bytes: 256
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  ll sumA=0;
  ll sumB=0;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
    sumA+=A[i];
  }
  vector<ll> B(N);
  REP(i, N){
    cin >> B[i];
    sumB+=B[i];
  }  

  if(sumB<sumA){
    cout << "No" << endl;
  }else{
    ll xA = sumB-sumA;
    ll xB = sumB-sumA;
    REP(i,N){
      if(A[i]>B[i]){
        xB-=A[i]-B[i];
      }else if(A[i]<B[i]){
        if((B[i]-A[i])%2==0){
          xA-=(B[i]-A[i])/2;
        }else{
          xA-=(B[i]-A[i])/2+1;
        }
        xB-=(B[i]-A[i])%2;
      }
    }
    if(xA*2==xB&&xA>=0&&xB>=0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string str;
		double lg,sh;
		cin>>str;
		lg=atoi(str.substr(0,2).c_str())*30;
		sh=((atoi(str.substr(3,2).c_str())))*6;
		lg+=((double)sh/12);
		double dis=abs(lg-sh);
		dis=min(dis,360-dis);
		if((dis>0||EQ(dis,0))&&dis<30){
			cout<<"alert"<<endl;
		}
		else if((dis>90||EQ(dis,90))&&(dis<180||EQ(dis,180))){
			cout<<"safe"<<endl;
		}
		else{
			cout<<"warning"<<endl;
		}
	}
	return 0;
}

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

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

  int cnt=0;
  if (s[0]!='A') {
    cout << "WA";
    return 0;
  } else {
    for (int i=1; i<s.size(); i++) {
      if (s[i]>='a' && s[i]<='z') cnt++;
    }
    if (cnt!=s.size()-2) {
      cout << "WA";
      return 0;
    }
  }

  cnt=0;
  for (int i=2; i<s.size()-1; i++) {
    if (s[i]=='C') cnt++;
  }

  if (cnt==1) cout << "AC";
  else cout << "WA";

}

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

#pragma warning(disable:4996)
using namespace std;

const int X=100000;
vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}
int main() {
	vector<vector<long long int>>dp(X+1,vector<long long int>(25));
	for (int num = 1; num <= X; ++num) {
		for (int k = 0; k < 24; ++k) {
			if (k == 0) {
				dp[num][0]=1;
			}
			for (int next = num * 2; next <= X; next += num) {
				dp[next][k+1]+=dp[num][k];
			}
		}
	}
	int N;cin>>N;int K;cin>>K;K--;
	if (K >= 20) {
		cout<<0<<endl;
	}
	else {

		long long int answer = 0;
		for (int i = 1; i <= N; ++i) {
			answer += dp[i][K];
		}
		cout << answer << endl;
	}
	return 0;
}



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

using namespace std;

const int N = 1e5 + 5 , M = 5;

int n;
int happiness[N][M];

int mem[N][M]; // definition: maximum happiness by doing activity M on day N

int dp(int day , int lastActivity){

    // last day
    if(day == n) return 0;

    if(mem[day][lastActivity] != -1) return mem[day][lastActivity];


    int ans = 0;

    // try to do an activity on this day
    for(int newActivity = 0 ; newActivity < 3 ; newActivity ++){

            // this activity must not be equal to the activity that have been done on the day before
            if(newActivity != lastActivity){

                    ans = max(ans , happiness[day][newActivity] + dp(day + 1 , newActivity));

            }
    }

    mem[day][lastActivity] = ans; // saving the answer of this state

    return mem[day][lastActivity]; // returning the answer of this state after saving
}


main(){

    scanf("%d" , &n);

    for(int day = 0 ; day < n ; day ++){

            for(int activity = 0 ; activity < 3 ; activity ++){

                    scanf("%d" , &happiness[day][activity]);

            }
    }

    int ans = 0;

    memset(mem , -1 , sizeof mem);

    // try to do first 3 activities
    for(int activity = 0 ; activity < 3 ; activity ++){

            ans = max(ans , happiness[0][activity] + dp(1 , activity));

    }

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

    return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[200005],ans;
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
		cin>>a[i];
	for (int i=2;i<=n;++i)
		a[i]+=a[i-1];
	ans=abs(a[1]-(a[n]-a[1]));
	for (int i=2;i<n;++i)
		ans=min(ans,abs(a[i]-(a[n]-a[i])));
	cout<<ans;
}

Measured memory_bytes: 1792