akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  long maxx;
  long answer = 0;
  vector<long> x(N),y(N),z(N),total(N);
  for (int i=0; i<N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  for (int i=0; i<2; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<2; k++) {
        maxx = 0;
        for (int l=0; l<N; l++) {
          total[l] = x[l] + y[l] + z[l];
        }
        sort(total.begin(),total.end());
        reverse(total.begin(),total.end());
        for (int p=0; p<M; p++) {
          maxx += total[p];
        }
        /*cerr << maxx << endl;*/
        if (maxx > answer) {
          answer = maxx;
        }
        for (int t=0; t<N; t++) {
          z[t] = z[t] * -1;
        }
      }
      for (int u=0; u<N; u++) {
          y[u] = y[u] * -1;
      }
    }
    for (int v=0; v<N; v++) {
          x[v] = x[v] * -1;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if i>0:
        if a[i]==a[i-1]+1:
            ans+=c[a[i-1]-1]
print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
    int ans;
    int n=s.size(),m=t.size();
    ans=m;
    int countt=0;
    for(int i=0;i<n-m+1;i++)
    {   countt=0;
        string temp=s.substr(i,m);

        for(int j=0;j<m;j++)
        {
            if(temp[j]!=t[j])
                countt++;
        }
        //cout<<countt<<endl;
        ans=min(ans,countt);
    }
    cout<<ans;
}


Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cfloat>
#include <cmath>
#include <functional>
#include <forward_list>
#include <list>


#define DEBUG(x) cout << #x << "\t:" << x << endl;
#define EPS (1e-9)
#define INF (INT_MAX/2)
#define MOD 1000000007
#define PI 3.14159265358979
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REPV(it,v) for(auto it = (v).begin(); it != (v).end(); ++it)

#define NUM 5000

#define ll long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> iiPair;


class Main {
public:
	bool winnable(vector<ll>& hs, ll n, ll a, ll b) {
		ll sum = 0;
		REP(i, hs.size()) {
			ll rest = hs[i] - n * b;
			ll more = a - b;
			if (rest > 0) {
				sum += (rest + more - 1) / more;
			}
		}
		bool res = (sum <= n);
		return res;
	}

	ll getAns(vector<ll>& hs, ll a, ll b) {
		ll left = 0;
		ll right = (ll)(INT_MAX/2);

		while (right - left > 1) {
			ll mid = (left + right) / 2;
			if (winnable(hs, mid, a, b)) {
				right = mid;
			}
			else {
				left = mid;
			}
		}
		return right;
	}
};

int main(void) {
	Main main;
	int n,a,b;
	vector<ll> hs;
	cin >> n >> a >> b;
	REP(i, n) {
		int inp;
		cin >> inp;
		hs.push_back(inp);
	}

	cout << main.getAns(hs, a, b) << endl;

	return 0;
}

Measured memory_bytes: 1400
s = list(input())
before = []
cnt = 0
for i,now in enumerate(s):
    if i == 0 or len(before) == 0:
        before.append(now)

        continue
    if before[-1] != now:
        before.pop()
        cnt += 2
    else:
        before.append(now)

print(cnt)


Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005,mod=998244353;
int k,n,c[N][N];
ll C(int n,int m)
{
    if(m==0||n==m) return 1;
    if(m==1) return n;
    if(c[n][m]) return c[n][m];
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
ll solve(int x)
{
    ll ans=0;
    int up=0;
    for(int i=1;i<=x/2;i++)
        if(i<=k&&x-i<=k)
        up++;
    for(int j=0,f=1;j<=up&&n-2*j>=0;j++,f*=-1)
        ans=(ans+f*C(up,j)%mod*C(n-2*j+k-1,k-1))%mod;
    return (ans+mod)%mod;
}
int main()
{
    scanf("%d%d",&k,&n);
    for(int i=2;i<=2*k;i++)
        printf("%lld\n",solve(i));
}


Measured memory_bytes: 60800
#include <bits/stdc++.h> 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;
 
const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;
 
/*
  filippos
  Contest : AtCoder DP contest
  Task : O - Catching
*/
 
int main(){
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

  int n; cin >> n;
  vector<vb> ok(n, vb(n));
  for(auto &v : ok)
    for(int i = 0; i < n; i++){
      bool x; cin >> x;
      v[i] = x;
    }

  const int MOD = 1e9 + 7;
  vvi memo(n, vi(1 << n, -1));
  function<int(int, int)> dp = [&](int i, int mask){
    if(i == n) return 1;
    int &ans = memo[i][mask];
    if(ans != -1) return ans;
    ans = 0;
    for(int j = 0; j < n; j++) if (ok[i][j])
      if((mask & (1 << j)) == 0)
        ans = (ans + dp(i+1, mask | (1 << j))) % MOD;
    return ans;
  };

  cout << dp(0, 0);

  return cout << endl, 0;
}

Measured memory_bytes: 180608
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String x;for(int t=s.nextInt(),r,p,o,b;t-->0;System.out.println(p))for(r=p=o=0;!(x=s.next()).equals("OUT")||++o<3;){if(x.equals("HIT")){b=r>2?1:0;p+=b;r+=1-b;}if(x.matches("H.+N")){p+=r>2?4:r+1;r=0;}}}}

Measured memory_bytes: 12000
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    if("7" in S):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int count;
		while ((count = in.nextInt()) > 0) {
			int[] ice = new int[10];
			while (count-- > 0) {
				ice[in.nextInt()]++;
			}
			for (int b : ice) {
				if (b != 0) {
					char[] c = new char[b];
					Arrays.fill(c, '*');
					System.out.println(c);
				} else {
					System.out.println('-');
				}
			}
		}
	}
}

Measured memory_bytes: 51868
fn main() {
    let (h, w): (usize, usize) = (read(), read());
    if (h == 1) | (w == 1) {
        println!("1");
    } else {
        let p = h * w;
        if p % 2 == 1 {
            println!("{:?}", p / 2 + 1);
        } else {
            println!("{:?}", p / 2);
        }
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
	int A,B,C,n,R;
	while(cin>>A>>B>>C,A+B+C){
		int t=min(A*A+B*B,min(B*B+C*C,C*C+A*A));
		cin>>n;
		while(n--){
			cin>>R;
			cout<<(t<4*R*R?"OK":"NA")<<endl;
		}
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 1000000000;
  for (int i = 0; i <= 200000; i+= 2) {
    int tmp = i * c + max(0, x - i / 2) * a + max(0, y - i / 2) * b;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
int pow(int x, int p)
{
    int res=1;
    while(p)
    {
        if(p&1)
        {
            res=(res*x)%mod;
        }
        p=p/2;
        x=(x*x)%mod;
    }
    return res;
}

int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 
 
 
   int n,k; 
   cin>>n>>k;
    vector<int>v(n+1);
   vector<int>f(n+5),inv(n+5);
   f[0]=f[1]=inv[0]=inv[1]=1;

   for(int i=1;i<=n;i++)cin>>v[i];
   sort(v.begin()+1,v.end());

   for(int i=2;i<=n+1;i++)
   {
       f[i]=(f[i-1]*i)%mod;
       inv[i]=pow(f[i],mod-2);
   }
   int val1=0,val2=0;

   for(int i=k;i<=n;i++)
   {
       val1=(val1+(((f[i-1]*inv[k-1])%mod*inv[i-k])%mod * v[i])%mod ) %mod;
   }

   for(int i=1;i<=n-k+1;i++)
   {
       val2=(val2 + (((f[n-i]*inv[n-i-k+1])%mod * inv[k-1])%mod * v[i])%mod )%mod;
   }

   int ans=(val1-val2+mod)%mod;
   cout<<ans<<"\n";


}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
double ans;
int  n;
int a[1005];
int main()
{
	cin>>n;
	int j=1,s=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans+=(double)1/a[i];
	}
	ans=(double)1/ans;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;

int N;
char str[MaxN];
char ans[MaxN];
char dif(char ch)
{
    if (ch=='S') return 'W';
    else return 'S';
}
bool dfs(int index)
{
    if(index > N)
    {
        bool flag;
        if(ans[1] =='S')
        {
            if(str[1] == 'o') flag = ans[N]==ans[2];
            else flag = ans[N]!=ans[2];
        }
        else
        {
            if(str[1] == 'x') flag = ans[N]==ans[2];
            else flag = ans[N]!=ans[2];
        }
        if(ans[N] =='S')
        {
            if(str[N] == 'o') flag = flag&&ans[1]==ans[N-1];
            else flag = flag&&ans[1]!=ans[N-1];
        }
        else
        {
            if(str[N] == 'x') flag = flag&&ans[1]==ans[N-1];
            else flag = flag&&ans[1]!=ans[N-1];
        }
        return flag;
    }
    if(index<=2)
    {
        ans[index] = 'S';
        if( dfs(index+1)) return true;
        ans[index] = 'W';
        if( dfs(index+1)) return true;
        else return false;
    }
    else
    {
        if(ans[index-1] == 'S')
        {
            if(str[index-1] == 'o')
            {
                ans[index] = ans[index-2];
                return dfs(index+1);
            }
            else
            {
                ans[index] = dif(ans[index-2]);
                return dfs(index+1);
            }
        }
        else
        {
            if(str[index-1] == 'x')
            {
                ans[index] = ans[index-2];
                return dfs(index+1);
            }
            else
            {
                ans[index] = dif(ans[index-2]);
                return dfs(index+1);
            }
        }
    }
}

void solve()
{
    if(dfs(1)) printf("%s\n", ans+1);
    else puts("-1");
}
int main()
{
    //std::ios::sync_with_stdio(false);
    scanf("%d", &N);
    scanf("%s", str+1);
    solve();
    //system("pause");
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    string S[N];
    int P[N];
    int ans[N];

    for(int i = 0; i < N; i++){
        ans[i] = 0;
        cin >> S[i] >> P[i];
        int cnt = 0;
        for(int j = 0; j < i; j++){
            if( S[i] < S[j] ){
                cnt++;
                ans[j]++;
            }else if( S[i] == S[j] ){
                if( P[i] > P[j] ){
                    cnt++;
                    ans[j]++;
                }
            }
        }
        ans[i] += (i - cnt + 1);
    }

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

    return 0;
}

Measured memory_bytes: 256
a,b,c,k = map(int,input().split())
if k%2 == 0:
    if abs(a-b) >= 10**18:
        print("Unfair")
    else:
        print(a-b)
else:
    if abs(a-b) >= 10**18:
        print("Unfair")
    else:
        print(b-a)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  int ans=1;
  
  long long x=pow(10,9)+7;
  
  
  for(int i=1;i<=N;i++){
    ans=(ans*(i%x))%x;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3500
//#define __popcnt __builtin_popcount
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define sz(a) ((int)(a).size())
#define all(n) (n).begin(),(n).end()
#define EPS 1e-6
#define OO 1e9
#define PI acos(-1.0)
#define ll long long
#define endl "\n"
#define scl(x) scanf("%lld",&x)
#define sc(x)  scanf("%d",&x)
#define sch(x)  scanf("%c",&x)
#define scs(x)  scanf("%s",x)
#define prl(x) printf("%lld",x)
#define pr(x)  printf("%d",x)
#define prs(x) printf("%s",x)
#define prline printf("\n");

void file(){
#ifndef ONLINE_JUDGE
	freopen("a_input.txt", "r", stdin);
	freopen("a_output.txt", "w", stdout);
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int dx[] = { -1, 0, 0, 1, 1, 1, -1, -1 };
int dy[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
//280,000
//1400

int main()
{
	/***  بسم الله الرحمن ا لرحيم   ***/
	//file();
	fast();
	int n;
	cin >> n;
	map<int, int> mp;
	while (n--){
		int a;
		cin >> a;
		mp[a]++;
	}
	int sum = 0;
	for (auto i:mp)
	if (i.first < i.second)sum += i.second - i.first;
	else if (i.first>i.second)sum += i.second;
	cout << sum;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n; cin >>n;
  vector<int> s(n),l(n),p(n);
  rep(i, n) cin >>s.at(i) >>l.at(i) >>p.at(i);
  int m; cin >>m;
  vector<int> w(m);
  rep(i, m) cin >>w.at(i);
  vector<int> res(m);
  bool ok = true;

  vector<int> dp;

  for (int melody=0; melody<m; melody++){
    int W = w.at(melody);
    dp.assign(W+1, 0);
    // dp[i]...長さiで得られる最高得点
    for (int i=0; i<n; i++){
      if (i>0) if (s.at(i) == s.at(i-1)) if (l.at(i) == l.at(i-1)) if (p.at(i) == p.at(i-1)) continue;
      for (int j=0; j<=W; j++){
        for (int k=s.at(i); k<=l.at(i); k++){
          if (j+k <= W) chmax(dp[j+k], dp[j] + p.at(i));
          else break;
        }
      }
    }
    res.at(melody) = dp[W];
    if (dp[W] == 0) ok = false;
  }

  if (ok) for (int melody=0; melody<m; melody++) cout <<res.at(melody) <<endl;
  else cout <<-1 <<endl;
}



Measured memory_bytes: 3120
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			long sumX = mod(IntStream.range(0, n).mapToLong(i -> mod((2 * i + 1 - n) * scanner.nextLong())).sum());
			long sumY = mod(IntStream.range(0, m).mapToLong(i -> mod((2 * i + 1 - m) * scanner.nextLong())).sum());
			System.out.println(mod(sumX * sumY));
		}
	}

	/**
	 * @param l
	 * @return l mod MOD
	 */
	private static long mod(long l) {
		long result = l % MOD;
		return (result >= 0) ? result : result + MOD;
	}
}


Measured memory_bytes: 66336
#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mk make_pair
using namespace std;
int gcd(int a,int b){
    if(b==0)
     return a;
    return gcd(b,a%b);
}
int main(){
   
 int n;
 cin>>n;
 if(n==1)
  cout<<0;
 else
  cout<<1;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m,x;cin>>n>>m>>x;
    vi c(n);
    vvi a(n,vi(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
        }
    }
    int ans=1e9;
    rep(i,(1<<n)){
        int sum=0;
        vi b(m,0);
        for(int j=0;j<n;++j){
            if((i>>j)&1){
                sum+=c[j];
                rep(k,m){
                    b[k]+=a[j][k];
                }
            }
        }
        bool y=true;
        rep(j,m){
            if(b[j]<x){
                y=false;
                break;
            }
        }
        if(y){
            ans=min(ans,sum);
        }
    }
    if(ans<1e9)cout<<ans<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>


int main(void)
 {
     int a, b, c;
     scanf("%d %d %d", &a, &b, &c);
     if((a < b) && (b < c)){
         printf("Yes\n");
     } else {
         printf("No\n");
     }
     return 0;
 }

         
         

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

int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	rep(i,s1.size()+1)
	{
		dp[i][0] = i;
	}
	rep(j,s2.size()+1)
	{
		dp[0][j] = j;
	}

	int c;
	for (int i = 1; i <= s1.size(); ++i)
	{
		for (int j = 1; j <= s2.size(); ++j)
		{
			if (s1[i-1] == s2[j-1]) c = 0;
			else c = 1;

			dp[i][j] = min(dp[i-1][j]+1, min(dp[i][j-1]+1, dp[i-1][j-1]+c));
		}
	}
	cout << dp[s1.size()][s2.size()] << endl;
	return 0;
}


Measured memory_bytes: 7124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
using namespace std;

int main() 
{
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    int mod = 1000000007;
    
    long long S = 0;
    for (int i = 0; i < n; i++)
    {
        S += A[i];
    }
    long long ans = 0;
    long long s = S;
    for (int i = 0; i < n-1; i++)
    {
        s -= A[i];
        long long s_mod = s%mod;
        ans += s_mod*A[i];
        ans %= mod;
    }
    cout << ans << endl;
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  string S = input< string >();

  vector< int > ans(S.size());
  
  int cnt = 0;

  auto f = [&](char s) {
    int cnt = 0;
    range(i, 0, S.size()) {
      if (S[i] == s) cnt++;
      else {
        ans[i] += cnt / 2;
        ans[i - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }
  };

  whole(reverse, S);
  whole(reverse, ans);
  f('L');
  
  whole(reverse, S);
  whole(reverse, ans);
  f('R');

  cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


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

using namespace std;

int digit(int x) {
  if (x == 0)
    return 1;

  int ret = 0;
  while (x > 0) {
    ret++;
    x /= 10;
  }

  return ret;
}

int quick_pow10(int n) {
  static int pow10[10] = {1,      10,      100,      1000,      10000,
                          100000, 1000000, 10000000, 100000000, 1000000000};

  return pow10[n];
}

int main(int argc, char* argv[]) {
  int a, b;
  cin >> a >> b;

  int x = digit(b);
  int c = a * quick_pow10(x) + b;

  for (int i = 0; i * i <= c; i++) {
    if (i * i == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

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


int main(void){
  long int N,Q;
  long int K;
  long int *score;
  long int *A;
  scanf("%ld %ld %ld",&N,&K,&Q);
  score = calloc(N, sizeof(long int));
  A = calloc(Q, sizeof(long int));
  long int i;

  for (i = 1; i <= Q; i++) {
    scanf("%ld", &A[i]);
  }

  for (i = 1; i <= Q; i++) {
    score[A[i]] += 1;
  }

  for (i = 1; i <= N; i++) {
    if (K - Q + score[i] > 0) {
      puts("Yes");
    }else{
      puts("No");
    }
  }

  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B) cout << C << endl;
	if (A == C) cout << B << endl;
	if (C == B) cout << A << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  A.pb(A[0] + K);
  vector<int> d(N);
  rep(i, N) {
    d[i] = A[i + 1] - A[i];
  }
  sort(all(d), greater<int>());

  int ans = K - d[0];
  cout << ans << endl;
}

Measured memory_bytes: 4992
N, M = map(int, input().split())
X = list(map(int, input().split()))

x = sorted(X)

diff = []
for n in range(1, M):
	diff += [abs(x[n] - x[n - 1])]
diff.sort(reverse=True)

print(abs(x[-1] - x[0]) - sum(diff[:N - 1]))


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) (__gcd(a, b))
#define LCM(a, b) ((a)/GCD(a,b)*(b))
#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1550555;
const int M = 5125;

int cnt[N];
void solve() {
    int n;
    cin >> n;

    for (int x = 1; x <= 100; x++){
        for (int y = 1; y <= 100; y++){
            for (int z = 1; z <= 100; z++){
                int k = x*x + y*y + z*z + x*y + y*z + x*z;
                cnt[k]++;
            }
        }
    }

    for (int i = 1; i <= n; i++){
        cout << cnt[i] << endl;
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

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

    return 0;
}

Measured memory_bytes: 3812
n=int(input())
a=list(map(int,input().split()))

sum=1000
have=0

for i in range(n-1):
    if have==0:
        if a[i]<a[i+1]:
            mai=sum//a[i]
            buy=mai*a[i]
            sum=sum-buy
            have=1
        if a[i]>a[i+1]:
            continue
        if a[i]==a[i+1]:
            continue
    
    if have==1:
        if a[i]<a[i+1]:
            continue
        if a[i]>a[i+1]:
            sum=sum+a[i]*mai
            have=0
            continue
        if a[i]==a[i+1]:
            continue


if have==1:
    sum=sum+mai*a[n-1]

print(sum)

Measured memory_bytes: 61972
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

  int K, N;
  cin >> K >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  int ans = K - A[N-1] + A[0];
  for(int i=0;i<N-1;i++){
    ans = max(ans, A[i+1]-A[i]);
  }
  cout << K - ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 != 0 && b % 2 != 0) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


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

ll dp[110][110];

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> v(h,vector<bool>(w));
  rep(i,h)rep(j,w) {
    char c;
    cin >> c;
    if(c=='#') v[i][j] = false;
    else v[i][j] = true;
  }
  rep(i,h)rep(j,w) {
    ll a = 1e18;
    ll l = 1e18;
    if(i==0 && j==0) {
      if(!v[i][j]) dp[i][j] = 1LL;
      continue;
    }
    if(i!=0) {
      a = dp[i-1][j];
      if(!v[i][j] && v[i-1][j]) a++;
    }
    if(j!=0) {
      l = dp[i][j-1];
      if(!v[i][j] && v[i][j-1]) l++;
    }
    dp[i][j] = min(a,l);
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}

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

int main() {
  ll mod=1e9+7;
  ll vec[105];
  vec[0]=1,vec[1]=1;
  for(int i=2;i<105;i++){
    vec[i]=vec[i-1]+vec[i-2];
  }
  ll pair[101][101][2];
  for(int i=2;i<101;i++){
    for(int j=0;j<i;j++){
      if(j==0){
        pair[i][j][0]=vec[i];
        pair[i][j][1]=vec[i+1];
        continue;
      }
      if(j==1){
        pair[i][j][0]=vec[i+1];
        pair[i][j][1]=2*vec[i+1]-vec[i];
        continue;
      }
      pair[i][j][0]=pair[i-1][j-1][1];
      pair[i][j][1]=pair[i-1][j-1][1]+pair[i-1][j-1][0];
    }
  }
  int q;
  cin>>q;
  ll x,y,z=1;
  ll w=0;
  ll o,p,r;
  for(int i=0;i<q;i++){
    cin>>x>>y;
    if(x>y){
      swap(x,y);
    }
    if(y==1){
      cout<<"1 1"<<endl;
      continue;
    }
    for(int i=0;i<98;i++){
      if(vec[i]>x||vec[i+1]>y){
        z=i-1;
        break;
      }
    }
    cout<<z<<" ";
    if(z==1){
      cout<<(x%mod*y%mod)%mod<<endl;
      continue;
    }
    w=0;
    for(int j=0;j<z;j++){
      o=pair[z][j][0];
      p=pair[z][j][1];
      if(o>x||p>y){
        continue;
      }
      r=y-p;
      r/=o;
      w+=r+1;
      w%=mod;
      if(x>=p){
        r=x-p;
        r/=o;
        w+=r+1;
        w%=mod;
      }
    }
    cout<<w<<endl;
  }
}

Measured memory_bytes: 4224
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int n;
  while(cin>>n&&n){
    int a[50][30];
    memset(a,0,n*30*sizeof(int));
    for(i=0;i<n;i++){
      int p;
      cin>>p;
      for(j=0;j<p;j++){
	int q;
	cin>>q;
	q--;
	a[i][q]=1;
      }
    }
    int b[50][50];
    memset(b,0,n*50*sizeof(int));
    for(i=0;i<n;i++)
      b[i][i]=1;
    for(i=0;i<30;i++){
      int c[50];
      memset(c,0,n*sizeof(int));
      for(j=0;j<n;j++){
	if(a[j][i]){
	  for(k=0;k<n;k++)
	    c[k]|=b[j][k];
	}
      }
      for(j=0;j<n;j++){
	if(c[j]==0)
	  break;
      }
      if(j==n)
	break;
      for(j=0;j<n;j++){
	if(a[j][i])
	  memcpy(b[j],c,n*sizeof(int));
      }
    }
    if(i==30)
      cout<<-1<<endl;
    else
      cout<<i+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 880
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<int> x(n);
	for (auto& i : x)
		cin >> i;
	
	auto y = x;
	sort(y.begin(), y.end());

	for (const auto& i : x)
		cout << (i > y[n / 2 - 1] ? y[n / 2 - 1] : y[n / 2]) << endl;

	return 0;
}


Measured memory_bytes: 3712
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int arr[maxx << 2];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, x;
    cin >> n; n *= 3;
    long long res = 0;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    int cnt = 0;
    for (int i = n - 1; ; i -= 2) {
        res += arr[i];
        cnt++; if (cnt == n / 3) break;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll N = 100005;


int main(){
    //入力
    vector<int> v;
    ll n, m, A[N]; cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> A[i];
    vector<int> odds;
    vector<int> ans_A;
    for (int i = 0; i < m; i++) //奇数の抽出
    {
        if (A[i]%2==1)
        {
            odds.emplace_back(A[i]);
        }
        if (odds.size() == 3)
        {
            cout << "Impossible";
            return 0;
        }
    }
    if (odds.size() == 0)
    {
        for (int i = 0; i < m; i++)
        {
            ans_A.emplace_back(A[i]);
        }
    }
    else if (odds.size() != 0)
    {
        ans_A.emplace_back(odds[0]);
        for (int i = 0; i < m; i++)
        {
            if(A[i] % 2 == 1) continue;
            ans_A.emplace_back(A[i]);
        }
        if (odds.size() == 2)
        {
            ans_A.emplace_back(odds[1]);
        }
    }
    for (int i = 0; i < ans_A.size(); i++)
    {
        cout << ans_A[i] << " ";   //aの表示
    }
    cout << endl;
    int B_size = ans_A.size();
    if (ans_A.size()==1){
        B_size++;
        ans_A.emplace_back(1);
    }
    else
    {
        ans_A[ans_A.size()-1]++;
    }
    if (ans_A[0] == 1){
        B_size--;
    }
    cout << B_size << endl; //bの大きさの表示
    
    if (ans_A[0] != 1)
    {
        cout << ans_A[0]-1 << " ";
    }
    
    for (int i = 1; i < ans_A.size(); i++)
    {
        cout << ans_A[i] << " " ;
    }
    cout << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
ll p, t;

int main() {
    cin >> n;
    p = 1;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        ll g = __gcd(p, t);
        p = p / g * t;
    }
    cout << p << endl;
    return 0;
}


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

string S;
int K;
deque<int> d;
int counter=0;
long long ans=0;
bool allsame=true;

int main()
{
    cin>>S;
    cin>>K;

    char current=S[0];

    for (int i=0; i<S.size(); i++)
    {
        if (S[i]==current)
        {
            counter++;
        }

        else
        {
            d.push_back(counter);
            counter=1;
            current=S[i];
        }
    }

    d.push_back(counter);

    for (int i=0; i<d.size(); i++)
    {
        if (d[i]>1)
        {
            ans=ans+(d[i]/2);
        }
    }

    for (int i=0; i<S.size(); i++)
    {
        current=S[0];
        if (S[i]!=current)
        {
            allsame=false;
            break;
        }
    }

    if (allsame)
    {
        ans=1ll*K*S.size()/2;

    }

    else if (d.front()%2==1 && d.back()%2==1 && S[0]==S[S.size()-1])
    {
        ans=ans*K;
        ans=ans+K-1;
    }

    else
    {
        ans=ans*K;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3584
n = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for i in range(n)]
dp[0] = 0
dp[1] = dp[0] + (h[1] - h[0])
for i in range(1, n):
    dp[i] = min(dp[i - 2] + (abs(h[i] - h[i - 2])), dp[i - 1] + (abs(h[i] - h[i - 1])))
print(dp[n - 1])

Measured memory_bytes: 13928
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    vector<int> ch (26, 0);
    F0R(i, sz(s)) ch[s[i] - 'A']++;
    int r = 0;
    F0R(i, sz(ch))
    {
        if(ch[i] == 2) r++;
    }
    cout << (r == 2 ? "Yes" : "No");
    return 0;
}

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

int solve(const string& S) {
  // Initialize DP table
  const auto s_len = S.size();
  vector<int> dp(s_len, 0);

  dp[0] = 1;

  if (S.size() >= 2) {
    dp[1] = S.at(1) != S.at(0) ? 2 : 1;
  }

  if (S.size() >= 3) {
    dp[2] = (S.at(2) != S.at(1) && S.at(1) != S.at(0)) ? 3 : 2;
  }

  // DP
  for (auto i = 3; i < s_len; ++i) {
    if (S[i] != S[i - 1]) {
      dp[i] = max(dp[i], dp[i - 1] + 1);
    } else {
      dp[i] = max(dp[i], dp[i - 3] + 2);
    }
  }

  return dp[s_len - 1];
}

int main() {
  // Input
  string S;
  cin >> S;

  // Solve
  auto ans = solve(S);

  // Answer
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1284
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    L = len(S)
    pre = ''
    s = ''
    ans = 0
    for i in range(L):
        s += S[i]
        if s!=pre:
            ans += 1
            pre = s
            s = ''
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <iomanip>
#include <utility>
#include <bitset>
#include <set>
#include <map>
#include <ios>
#include <cstdlib>
using namespace std;
int main() {
    string S; cin >> S;
    int cnt=0;
    for (int i=0;i<S.size();i++){
        if (S[i]=='o') cnt++;
    }
    if (cnt+(15-S.size())>=8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define rep(i,n) repl(i,0,n-1)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
int main(){
  cin.sync_with_stdio(false);
  int count = 0;
  int two = 0;
  int N;
  cin >> N;
  int t;
  rep(i,N){
    cin>>t;
    if(t % 4 == 0)count++;
    else if(t % 2 == 0)two++;
  }
  cout << (N / 2 <= count+two/2 ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;

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

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


using namespace std;


int main(void) {
    string S;
    cin >> S;
    list<char> l;
    for (auto ch : S) {
        l.push_back(ch);
    }
    int Q;
    cin >> Q;
    bool reversed = false;
    for (int i = 0; i < Q; i++) {
        int T;
        cin >> T;
        if (T == 1) {
            reversed = !reversed;
            continue;
        }
        int F;
        char C;
        cin >> F >> C;
        if ((!reversed && F == 1) || (reversed && F == 2)) {
            l.push_front(C);
        } else {
            l.push_back(C);
        }
    }
    if (!reversed) {
        for (auto it = l.begin(); it != l.end(); ++it) {
            cout << *it;
        }
        cout << endl;
    } else {
        for (auto it = l.rbegin(); it != l.rend(); ++it) {
            cout << *it;
        }
        cout << endl;
    }
}


Measured memory_bytes: 13092
fn run() {
    proconio::input! {
        n: usize,
        m: usize,
        col: [(i64, i64, i64); n],
        row: [(i64, i64, i64); m],
    }
    let inf = 1_000_000_000i64 + 1;
    let mut x = vec![-inf, inf];
    let mut y = vec![-inf, inf];
    for &(a, b, c) in col.iter() {
        x.push(a);
        x.push(b);
        y.push(c);
    }
    for &(a, b, c) in row.iter() {
        x.push(a);
        y.push(b);
        y.push(c);
    }
    x.sort();
    x.dedup();
    y.sort();
    y.dedup();
    let mut h: Vec<_> = x.iter().map(|x| (*x, 0)).collect();
    let mut w: Vec<_> = y.iter().map(|x| (*x, 0)).collect();
    for x in x.windows(2) {
        h.push((x[0], x[1] - x[0]));
    }
    for y in y.windows(2) {
        w.push((y[0], y[1] - y[0]));
    }
    h.sort();
    w.sort();
    let mut board = vec![vec![false; w.len()]; h.len()];
    for &(a, b, c) in col.iter() {
        let l = h.binary_search(&(a, 0)).unwrap();
        let r = h.binary_search(&(b, 0)).unwrap();
        let y = w.binary_search(&(c, 0)).unwrap();
        for i in l..=r {
            board[i][y] = true;
        }
    }
    for &(d, e, f) in row.iter() {
        let x = h.binary_search(&(d, 0)).unwrap();
        let l = w.binary_search(&(e, 0)).unwrap();
        let r = w.binary_search(&(f, 0)).unwrap();
        for i in l..=r {
            board[x][i] = true;
        }
    }
    let mut dfs = std::collections::VecDeque::new();
    let cond = |x: (i64, i64)| x.1 > 0 && x.0 <= 0 && x.0 + x.1 >= 0;
    for (i, x) in h.iter().enumerate() {
        if !cond(*x) {
            continue;
        }
        for (j, y) in w.iter().enumerate() {
            if cond(*y) {
                board[i][j] = true;
                dfs.push_back((i, j));
            }
        }
    }
    let mut ans = 0i64;
    while let Some((a, b)) = dfs.pop_front() {
        ans += h[a].1 * w[b].1;
        for &(i, j) in [(a - 1, b), (a + 1, b), (a, b - 1), (a, b + 1)].iter() {
            if !(i < h.len() && j < w.len()) {
                println!("INF");
                return;
            }
            if !board[i][j] {
                board[i][j] = true;
                dfs.push_back((i, j));
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 37648
#include<iostream>
#include<set>
int GCD(int a, int b){
  if(b == 0) return a;
  else return GCD(b, a % b);
}
int main(){
  int n;
  int a, b, c;
  int num;
  std::cin >> n;
  if(n == 2){
    std::cin >> a >> b;
    num = GCD(a, b);
  }else if(n == 3){
    std::cin >> a >> b >> c;
    num = GCD(a, b);
    num = GCD(num, c);
  }
  std::set<int> sta;
  for(int i = 1; i * i <= num; i++){
    if(num % i == 0 && i * i == num) sta.insert(i);
    else if(num % i == 0){
      sta.insert(i);
      sta.insert(num / i);
    }
  }
  
  for(auto e : sta){
    std::cout << e << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
using namespace std;
signed main() {
	int cnt = 0;
	string n;
	cin >> n;
	for (int i = 0; i < n.size(); i++) {
		if (n[i] == '2')cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 768