akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	string S,SS;
	cin >> S;
	vector<char> v;
	fore(i,0,S.size()){
		v.push_back(S[i]);
	}
	sort(v.begin(),v.end());
	if(v[0]=='a'&&v[1]=='b'&&v[2]=='c'){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    double pai = 6.28318530717958623200;

    //cout << "Yes" << "No" << " " << endl;
    printf("%.10f\n", n * pai);
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int min = 1000000001, max = 0;
    for (int i=0; i<N; i++) {
        int v;
        cin >> v;
        if (min > v) min = v;
        if (max < v) max = v;
    }
    cout << (max - min) << endl;
    return 0;
}

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

int main() {
    int N;
    int sum = 0;
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        sum += (r-l+1);
    }
    cout << sum;
}
    


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int u, v; cin >> u >> v; u--, v--;
        G[u].push_back(v);
    }
    int s, t; cin >> s >> t; s--, t--;
    vector<vector<ll>> dist(n, vector<ll>(3, LINF));
    dist[s][0] = 0;
    queue<pii> que; que.push({s, 0});
    while(!que.empty()){
        auto p = que.front(); que.pop();
        int v = p.first, cost = p.second;
        int to = (cost + 1) % 3;
        for(auto e: G[v]){
            if(dist[e][to] != LINF)continue;
            dist[e][to] = dist[v][cost] + 1;
            que.push({e, to});
        }
    }
    ll res = dist[t][0];
    if(dist[t][0] == LINF) res = -1;
    else res /= 3;
    cout << res << ln;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll a,b,c;cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);

  out(a<<" "<<b<<" "<<c);


  return 0;
}


Measured memory_bytes: 256
import sys
A, B, C, D = list(map(int, input().rstrip()))

if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A, B, C, D))
    sys.exit()
elif A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A, B, C, D))
    sys.exit()
elif A-BC-D==7:
    print("{}-{}-{}-{}=7".format(A, B, C, D))
    sys.exit()
else:
    pass

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int d;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> d;
    if (d==22) cout << "Christmas Eve Eve Eve";
    else if (d==23) cout << "Christmas Eve Eve";
    else if (d==24) cout << "Christmas Eve";
    else cout << "Christmas";
}


Measured memory_bytes: 256
program minpro2019B
    implicit none
    integer(8)::i
    integer(8)::flg=0
    integer(8),dimension(6)::A
    integer(8),dimension(4)::L=0
    read(5,*)(A(i),i=1,6)

    do i=1,6
        L(A(i))=L(A(i))+1
    end do

    do i=1,6
        if(L(i)>=3)flg=1
    end do

    if(flg==1)then
        print'(A)',"NO"
    else
        print'(A)',"YES"
    end if
end program minpro2019B

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

char s[101];

void change(int a, int b){

  swap(s[a - 1], s[b - 1]);
  int n = b - a;
  n %= 26;
  int N = n;



  if(s[a - 1] + n > 'z'){
    n -= 'z' - s[a - 1];
    s[a - 1] = 'a' + --n;
  }else s[a - 1] += n;

  if(s[b - 1] + N > 'z'){
    N -= 'z' - s[b - 1];
    s[b - 1] = 'a' + --N;
  }else s[b - 1] += N;

}


int main(void){


  int dn;
  while(cin >> dn, dn){
    cin >> s;

    int a[101], b[101], cnt = 0;
    for(int i = 0 ; i < dn ; i++){
      cin >> a[i] >> b[i];
      cnt++;
    }
    for(int i = cnt - 1 ; i >= 0 ; i--){
      change(a[i], b[i]);
    }
    cout << s << endl;

  }

  return 0;
}

Measured memory_bytes: 1160
<?php
$n = trim(fgets(STDIN));
$map = [
  "M" => 0,  
  "A" => 0,  
  "R" => 0,  
  "C" => 0,  
  "H" => 0,  
];
for($i = 0; $i < $n; $i++){
    $c = fgets(STDIN)[0];
    if(isset($map[$c])){
        $map[$c]++;
    }
}
echo dfs($map,[])/6;
function dfs($map, $map2){
    if(count($map2) == 3){
        return array_product($map2);
    }
    $ret = 0;
    foreach($map as $k => $v){
        $m = $map;
        unset($m[$k]);
        $m2 = $map2;
        $m2[$k] = $v;
        $ret += dfs($m, $m2);
    }
    return $ret;
}





Measured memory_bytes: 4856
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

lli i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
  int n,k; cin>>n>>k;

 vll v;
  rep(i,0,n-1) 
  {
  	lli x; cin>>x; v.pb(x);
  }	

  int k1,k2,k3,k4;

lli max=0;

  rep(k1,0,n)
   rep(k2,0,n-k1)
    {
    	lli sum1=0,sum2=0;
        vll v1,v2;
       rep(i,1,k1)
            v1.pb(v[i-1]),sum1+=v[i-1];
       rep(i,1,k2)
            v2.pb(v[n-i]),sum2+=v[n-i];

          sort(all(v1)); sort(all(v2));
          rep(i,1,sz(v1)-1) v1[i]+=v1[i-1];
          rep(i,1,sz(v2)-1) v2[i]+=v2[i-1];
     
       rep(k3,0,k1)
        rep(k4,0,k2)
         if(k1+k2+k3+k4<=k)
         {
         	lli sum3=0,sum4=0;
         	if(k3>0) sum3=v1[k3-1];
         	if(k4>0) sum4=v2[k4-1];

         	max=max2(max,sum1+sum2-sum3-sum4);
         }
    }
    cout<<max<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<n;i++)
typedef long long int ll;
#define ALL(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 1<<31 - 1;
int main() {
   string s;int n,m;
  cin >>n;
  cout << (n+1) %2 << endl;
}

Measured memory_bytes: 3620
from math import gcd
K = int(input())
sum_gcd = [0]*201
ans = 0
 
for i in range(1,K+1):
  for j in range(1,K+1):
    sum_gcd[gcd(i,j)] += 1
for i in range(1,K+1):
  for k in range(1,K+1):
    ans += sum_gcd[i]*gcd(i,k)

print(ans)

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

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

    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) nums.push_back(cnt);

    if (nums.size() % 2 == 0) nums.push_back(0);

    int add = 2 * K + 1;
    int ans = 0;
    for (int i = 0; i < nums.size(); i += 2) {
        int tmp = 0;

        int left = i;
        int right = min(i + add, (int)nums.size());
        for (int j = left; j < right; j++) {
            tmp += nums[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a1 = (a + 9) // 10 * 10
b1 = (b + 9) // 10 * 10
c1 = (c + 9) // 10 * 10
d1 = (d + 9) // 10 * 10
e1 = (e + 9) // 10 * 10

tmax = 0
if tmax < a1 - a:
    tmax = a1 - a
if tmax < b1 - b:
    tmax = b1 - b
if tmax < c1 - c:
    tmax = c1 - c
if tmax < d1 - d:
    tmax = d1 - d
if tmax < e1 - e:
    tmax = e1 - e

print(a1+b1+c1+d1+e1-tmax)

Measured memory_bytes: 3316
import java.util.Scanner;


public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    String tt = T.substring(0,T.length()-1);
    if(S.equals(tt)) {
		System.out.println("Yes");
    } else {
		System.out.println("No");
    }


  }
}

Measured memory_bytes: 26932
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	ll N;
	cin >> N;
	vector<ll>v;
	v.push_back(1);
	for (ll i = 6; i <= 100000; i *= 6) {
		v.push_back(i);
	}
	for (ll i = 9; i <= 100000; i *= 9) {
		v.push_back(i);
	}

	ll dp[100000];
	for (ll i = 0; i <= 100000; i++) {
		dp[i] = 100000;
	}
	dp[0] = 0;
	for (ll i = 0; i < v.size(); i++) {
		for (ll j = 0; j + v[i] <= N; j++) {
			dp[j + v[i]] = min(dp[j + v[i]], (dp[j] + 1));
		}
    }
	cout << dp[N] << endl;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
h = [0] + list(map(int, input().split()))

INF = 1 << 30
dp = [INF] * (n + 1)
dp[0] = 0
dp[1] = 0

for i in range(2, n + 1):
	for j in range(1, k + 1):
		if i > j:
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))


print(dp[n])

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

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

ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}


int main(){
   ll a,b;cin>>a>>b;
   ll ans;
   ans=lcm(a,b);
   cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;
    VVL d(10, VL(10, 1e18));
    VL A(10, 0);

    rep(i, 0, 10){
        rep(j, 0, 10) cin >> d[i][j];
    }

    rep(h, 0, H){
        rep(w, 0, W){
            ll a; cin >> a;
            if(a != -1) A[a]++;
        }
    }

    rep(i, 0, 10){
        rep(j, 0, 10){
            rep(k, 0, 10){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }

    ll ans = 0;
    rep(i, 0, 10) ans += A[i] * d[i][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define  fs first
#define  sc second
int main(){
    ll n,m;cin>>n>>m;
    vector<ll> s(n);
    vector<ll> c(n);
    REP(i,m){
        cin>>s[i]>>c[i];
        s[i]--;
    }
    vector<char> pre(n,'0');
    vector<ll> cnt(n,-1);
    string ans;
    bool ok =true;
    REP(i,m){
        if(cnt[s[i]]==-1) cnt[s[i]]=c[i];
        else if(cnt[s[i]]==c[i]) continue;
        else {
            ans="-1";
            ok=false;
            break;
        }
    }
    if(ok){
        REP(i,m) pre[s[i]]=cnt[s[i]]+'0';
        for(auto tmp:pre) ans.push_back(tmp);
        if(n>1 && cnt[0]==-1) ans[0]='1';
        if(ans[0]=='0' && n>1) ans="-1";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii Dir[8] = { //?????????
	{ 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 },
	{ 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}

signed main() {
	int n;
	scanf("%d", &n);
	vector<pii> foo(n);
	REP(i, n) {
		scanf("%d %d", &foo[i].second, &foo[i].first);
	}
	sort(ALL(foo),greater<pii>());

	int l = 0, r = n+1;
	while (1) {
		int m = (l + r) / 2;

		bool f = 0;

		priority_queue<int> out;
		ll sum = 0;
		REP(i, n) {
			out.push(foo[i].second);
			sum += foo[i].second;
			if (out.size() > m) {
				sum -= out.top();
				out.pop();
			}
			if (out.size() == m && sum <= (ll)foo[i].first*m) {
				f = 1;
				break;
			}
		}

		if (f) {
			l = m;
		}
		else {
			r = m;
		}

		if (r - l <= 1) {
			printf("%d\n", l);
			break;
		}
	}

	return 0;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}


int main() {
	int i,  n, k, c = 0, sum = 0;
	c_p_c();
	// cout<<"Sd"<<endl;>
	// cin>>n>>k;
	int a,b,c1;
	int total;
	cin>>a>>b>>c1>>total;


	for (int i = 0; i < a+1; ++i)
	{
		/* code */
		for (int j = 0	; j < b+1; ++j)
		{
			/* code */
			for (int k = 0; k < c1+1; ++k)
			{
				/* code */
				int ans =500*i + 100 * j + 50* k;
				// watch(ans);
				if(ans == total)
					c++;
			}
		}
	}

	cout<<c<<endl;







}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main() {
    string str;
    int numa = 99999;
    int numz = 0;
    cin >> str;
    for (int i = 0; i < str.size(); ++i) {
        if(str[i] == 'A') {
            numa = min(numa,i);
        }
        if(str[i] == 'Z'){
            numz = max(numz,i);
        }
    }

    cout << numz - numa +1;
    return 0;
}

Measured memory_bytes: 640
import copy
import itertools

h, w, k = map(int, input().split())
#s= list(input())

s = []
min = 100000
for i in range(h):
    s.append( [int(s) for s in list(input())])
    #s.append([1]*w)

dbg_cnt = 0
l = list(range(h-1))
for i in range(h):
    p = list(itertools.combinations(l, i))
    for j in p:
        tmp = list(j)
        tmps = []
        q = 0
        tmps.append([])
        #print(dbg_cnt)
        #dbg_cnt += 1
        for r in range(h):
            tmps[q].append(copy.copy(s[r]))
            if(q < len(tmp) and r==tmp[q]):
                tmps.append([])
                q += 1
        #print(tmps)
        count = i
        sums = [0] * len(tmps)
        precut = 1
        exitflg = 0
        for r in range(w): #550000
            for q in range(len(tmps)):
                for t in tmps[q]:
                    sums[q] += t[r] #5500000
            cutflg = 0
            for q in range(len(tmps)):
                if sums[q] > k : #5500000
                    cutflg = 1
            if cutflg == 1:
                #print('cut')
                count += 1
                sums = [0] * len(tmps)
                for q in range(len(tmps)):
                    for t in tmps[q]:
                        sums[q] += t[r] #5500000
            for q in range(len(tmps)): #5500000
                if sums[q] > k :
                    exitflg = 1
                    #print('exit')
        #print(exitflg)
        if exitflg == 0:
            if min > count:
                min = count
print(min)

Measured memory_bytes: 54236
#include <cstdio>

const int MN = 200005;

int N, p[MN], q[MN];
int t[MN], f[MN];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &p[i]), q[p[i]] = i;
	t[N] = 0;
	for (int i = N - 1; i >= 1; --i) {
		if (t[i + 1] == 0) {
			if (q[i] > q[i + 1]) t[i] = 1, f[i] = i + 1;
			else t[i] = 0;
		} else {
			if (/* 1. */ (q[i] < q[i + 1] && q[i + 1] < q[f[i + 1]]) ||
			/*     2. */ (q[i + 1] < q[f[i + 1]] && q[f[i + 1]] < q[i]) ||
			/*     3. */ (q[f[i + 1]] < q[i] && q[i] < q[i + 1]))
				t[i] = t[i + 1], f[i] = f[i + 1];
			else t[i] = t[i + 1] + 1, f[i] = i + 1;
		}
	}
	printf("%d\n", t[1]);
	return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>
#include<set>
using namespace std;

long long int n,t,x,a[200005],two[50]={1},cou=0,memo,res=0,id;
stack<long long int>stk;
priority_queue<long long int>pq;
int kukan=0;
string str,tmp;

int main(){
	cin>>n;
	for(int i=0;i<46;i++)
	{
		two[i+1]=2*two[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	
	for(int i=35;i>=0;i--)
	{
		cou=0;
		id=-1;
		for(int j=0;j<n;j++)
		{
			if(a[j]%two[i+1]==two[i])
			{
				id=j;
				cou++;
			}else if((a[j]/two[i])%2==1){
				cou++;
			}
		}
		
		if(i==0)
		{
			break;
		}
		
		if(cou%2==1&&id==-1)
		{
			cout<<-1<<endl;
			return 0;
		}else if(cou%2==1&&id!=-1){
			a[id]--;
			res++;
			
		//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
			//cout<<i<<endl;
		}
	}
	
	//cout<<cou;
	if(cou>res&&cou%2==1)
	{
		
		cout<<res+1<<endl;
	}else if(cou%2==0)
	 {
	 	cout<<res<<endl;
	 }
	else{
		//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
		cout<<-1<<endl;
		
	}
}


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

struct student{
    int x, y;
};
struct point{
    int x, y;
};

int cal(int x1,int x2,int y1,int y2){
    int x, y;

    if(x1 - x2 < 0){
        x = x2 - x1;
    }
    else{
        x = x1 - x2;
    }
    if(y1 - y2 < 0){
        y = y2 - y1;
    }
    else{
        y = y1 - y2;
    }

   // cout << x + y << endl;

    return (x + y);
}

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

    vector<student> student(n);
    vector<point> point(m);

    for(int i = 0; i < n; i++){
        cin >> student[i].x >> student[i].y;
    }
    for(int i = 0; i < m; i++){
        cin >> point[i].x >> point[i].y;
    }

    for(int i = 0; i < n; i++){
        int ans = 1000000000;
        for(int j = 0; j < m; j++){
            int tmp;
            tmp = cal(student[i].x, point[j].x, student[i].y, point[j].y);
            //ここにバグある同じ距離の時うまくいまない(# ﾟДﾟ)
            if(tmp < ans){
                ans = tmp;
                check = j;
            }
        }
        cout << check + 1 << endl;
        //ans = 1000000;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
 
#define pi 3.1415926535

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

  int sum = 0;
  for(int i = 0; i < n.size(); i++){
    sum += (int)n[i] - 48;
    sum = sum % 9;
  }

  if(sum == 0){
    cout << "Yes" << endl;
    return 0;
  }

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

Measured memory_bytes: 3756
from collections import Counter
N = int(input())
S = input()

west_side = Counter()
east_side = Counter(S)


min_num = 1000000
for k in range(N):
    tmp = S[k]

    if tmp == "E":
        east_side["E"] -= 1
    else:
        east_side["W"] -= 1
    num_of_change_vector = east_side["E"] + west_side["W"]
    if min_num > num_of_change_vector:
        min_num = num_of_change_vector

    if tmp == "E":
        west_side["E"] += 1
    else:
        west_side["W"] += 1

print(min_num)


Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  
  vl sides;
  rep(i, n) {
    if(sides.size()>=2) break;
    
    if(a[i]==a[i+1]) {
      sides.push_back(a[i]);
      i++;
    }
  }
  
  cout << (sides.size()>=2 ? sides[0] * sides[1] : 0LL) << newl;
  return 0;
}

Measured memory_bytes: 3960
program c175
 
implicit none
integer(16) :: x, k, d, a, s, l, t
 
read *, x, k, d
 
a = int(abs(x) / d)
s = abs(x) - a * d

!print *, s

if(abs(s) > abs(s-d)) then
 l = abs(s)
 s = abs(s-d)
 t = 1
else
 s = abs(s)
 l = abs(s-d)
 t = 0
end if
 
!print '(3(I5))', a, s, l
 
a = k - int(abs(x) / d) - t
 
if(abs(x) > d * k) then
 print *, abs(x) - d * k
else if(mod(a, 2) == 0) then
 print *, s
else if(mod(a, 2) == 1) then
 print *, l
end if
 
end program c175

Measured memory_bytes: 2812
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    string cip;
    getline(cin, cip);

    while(getline(cin, cip)) {
        bool hit = false;
        for(int a = 1; a < 26; a++) {
            if ( a % 2 == 0 || a == 13 )    continue;
            for(int b = 0; b < 26; b++) {
                string test = cip;
                for(int c = 0; c < cip.length(); c++) {
                    if ( cip[c] != ' ' ) test[c] = ((cip[c] - 'a') * a + b) % 26 + 'a';
                }
                if ( test.find("this") != string::npos || test.find("that") != string::npos ) {
                    hit = true;
                    cip = test;
                    break;
                }
            }
            if(hit) break;
        }
        cout << cip << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
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;
    vector<int> vec;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    vector<int> ruiseki;
    ruiseki.push_back(vec.front());
    for(int i = 1;i < N;i++){
        ruiseki.push_back(gcd(ruiseki.back(), vec.at(i)));
    }
    vector<int> ru;
    ru.push_back(vec.back());
    for(int i = N-2;i >= 0;i--){
        ru.push_back(gcd(ru.back(), vec.at(i)));
    }
    reverse(ru.begin(), ru.end());
    int ans = 0;
    ans = max(ans, ruiseki.at(N-2));
    ans = max(ans, ru.at(1));
    for(int i = 1;i < N-1;i++){
        ans = max(ans, gcd(ruiseki.at(i-1), ru.at(i+1)));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
 
using namespace std;
 
int main() {
  long long N, A, B, ans;
  cin >> N >> A >> B;
  long long x = N / (A + B);
  ans = A * x + min(A, N - ((A + B) * x));
  cout << ans << endl;
  
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

int N;
double dp[301][301][301];

double dfs(int i, int j, int k) {
    if (i == 0 && j == 0 && k == 0) return 0;
    if (dp[i][j][k]) return dp[i][j][k];
    double p0 = (1.0 * N - i - j - k) / N;
    double p1 = 1.0 * i / N;
    double p2 = 1.0 * j / N;
    double p3 = 1.0 * k / N;

    double ret = p0;
    if (i != 0) ret += p1 * (1 + dfs(i - 1, j, k));
    if (j != 0) ret += p2 * (1 + dfs(i + 1, j - 1, k));
    if (k != 0) ret += p3 * (1 + dfs(i, j + 1, k - 1));

    return dp[i][j][k] = ret / (1.0 - p0);
}

void solve() {
    cin >> N;
    vector<int> cnt(4, 0);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    cout << dfs(cnt[1], cnt[2], cnt[3]) << endl;

}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 213248
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1010;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 1e9 + 7;
int n , m;
char a[maxn][maxn];
int dp[maxn][maxn];
string in;

signed main() {
    
    fio;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> in;
        for(int j = 0; j < m; j++){
            a[i][j + 1] = in[j];
        }
    }
    
    dp[1][1] = 1;
    for(int i = 2; i <= n; i++) dp[i][1] = (a[i][1] == '#' ? 0LL : dp[i - 1][1]);
    for(int i = 2; i <= m; i++) dp[1][i] = (a[1][i] == '#' ? 0LL : dp[1][i - 1]);
    for(int i = 2; i <= n; i++){
        for(int j = 2; j <= m; j++){
            if(a[i][j] == '#') continue;
            if(a[i - 1][j] == '.'){
                dp[i][j] += dp[i - 1][j];
                dp[i][j] %= mod;
            }
            if(a[i][j - 1] == '.'){
                dp[i][j] += dp[i][j - 1];
                dp[i][j] %= mod;
            }
        }
    }
    
    cout << dp[n][m] << endl;
    
    
    return 0;
    
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,p;
	cin >> n >> p;
	vector< vector<ll> > dp = vector< vector<ll> > (2,vector<ll>(n+1,0));
	dp[0][0] = 1;
	dp[1][0] = 0;
	REP(i,n){
		int x;
		cin >> x;
		if(x%2==0){
			dp[0][i+1] = dp[0][i]*2;
			dp[1][i+1] = dp[1][i]*2;
		}else{
			dp[0][i+1] = dp[0][i]+dp[1][i];
			dp[1][i+1] = dp[0][i]+dp[1][i];
		}
	}
	DUMP(dp);
	cout << dp[p][n] << endl;
	return 0;
}

Measured memory_bytes: 256
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<LL,LL>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
const int mod = 1000000007;
map<pii,int> mp,vis;
LL a,b,sum,c,d;
LL qpow(LL a,LL x){
    LL res = 1;
    while(x){
        if(x&1) res = res * a % mod;
        a = a * a % mod;
        x >>= 1;
    }
    return res;
}
pii deal(LL a,LL b){
    LL aa = (a<0?-a:a);
    LL bb = (b<0?-b:b);
    LL g = __gcd(aa,bb);
    aa /= g; bb /= g;
    pii c = pii(aa,bb);
    if(a<0&&b>0) c.x = -c.x;
    if(a>0&&b<0) c.x = -c.x;
    return c;
}
int main(){
    int n; cin >> n ;
    for(int i = 1;i <= n; ++i){
        cin >> a >> b;
        if(a==0&&b==0){
            sum += 1;
            continue;
        }
        if(a==0){
            c += 1;
            continue;
        }
        if(b==0){
            d += 1;
            continue;
        }
        mp[deal(a,b)] += 1;
        vis[deal(-b,a)] += 1;
    }
    LL ans = max(1ll,qpow(2,c)+qpow(2,d)-1);
    map<pii,int>::iterator it = mp.begin();
    while(it != mp.end()){
        if(it->second == 0) {it++; continue;}
        LL num = qpow(2,it->second)-1;
        if(vis.count(it->first)){
            num += qpow(2,vis[it->first])-1;
            mp[deal(-(it->first).y,it->first.x)] = 0;
        }
        ans = ans * (num+1) % mod;
        it++;
    }
    if(sum == n) cout << sum << '\n';
    else cout << (ans + sum - 1 + mod) % mod << '\n';
    return 0;
}

Measured memory_bytes: 28544
#include<cstdio>
#include<cstring>

const int N=200000;

int del,t,len;
char s[N+5];

int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(s[i] == 'S')
			t++;
		else
			t?t--,del+=2:1;
	}
	printf("%d\n",len-del);
	return 0;
}

Measured memory_bytes: 384
/*
 *  author: chw0501
 *  created: 15.04.2020 11:24:07(UTC)
*/
#include <bits/stdc++.h>

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

int n;

//dp[i][j]: a[i]~a[j]까지 수가 남았을때 현재 플레이어가 얻을 수 있는 최대 점수
ll dp[3001][3001];
ll a[3001];
ll sum[3001];

ll solve(int i,int j){
	ll& ret=dp[i][j];
	if(ret!=-1ll) return ret;
	if(i==j) return ret=a[i];
	ret=0;
	ll s=sum[j]-sum[i-1];
	ret=max(ret,s-solve(i+1,j));
	ret=max(ret,s-solve(i,j-1));
	return ret;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
		sum[i]=sum[i-1]+a[i];
	}
	memset(dp,-1ll,sizeof(dp));
	ll x=solve(1,n);
	ll y=sum[n]-x;
	cout<<x-y;
	return 0;
}

Measured memory_bytes: 70784
#!/usr/bin/env python3
#ABC131 C
import sys
import math

A,B,C,D = list(map(int,input().split()))

def gcd(x,y):
    while y:
        x,y = y, x % y
    return x
def lcm(x,y):
    return x * y // gcd(x,y)

sub = B - A
c = A
ans = B
ans -= B // C
ans -= B // D
ans += B // (lcm(C,D))
c -= A // C
c -= A // D
c += A // (lcm(C,D))
if A % C != 0 and A % D != 0:
    ans += 1
ans -= c
print(ans)

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= (j);i--)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}
const int maxn = 1e5+5;
LL S[maxn];

int main()
{
    int N;
    scanf("%d",&N);
    _for(i,0,N){
        cin >> S[i];
    }

    LL ans = S[N-1];

    _for(C,1,N){
        LL num = S[N-1];
        _for(k,1,N){
            int A = N-1-k*C;
            if(C >= A || (!(A%C) && A/C <= k)) break;
            //cout << "C:" << C <<" "<<"A:"<<A<<endl;
            num += S[k*C];
            num += S[A];
            ans = max(ans,num);
            //cout << "num: "<<num <<endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+11,INF=~0u>>2;
char s[N];
int ans1=-1,ans2=-1,n;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<n;++i) if(s[i]==s[i+1]){
		printf("%d %d",i,i+1);
		return 0;
	}
	for(int i=1;i<n-1;++i){
		if(s[i]==s[i+2]){
			printf("%d %d",i,i+2);
			return 0;
		}
	}
	printf("-1 -1");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> x(N);
  std::vector<int> neg(N);
  std::vector<int> pos(N);
  for (auto &i : x) {
    std::cin >> i;
  }
  for (int i = 0; i < N; ++i) {
    neg[i] = x[i] < 0 ? -x[i] : 1000000009;
    pos[i] = x[i] > 0 ? x[i] : 1000000009;
    if (x[i] == 0) { --K; }
  }
  neg.push_back(0);
  pos.push_back(0);
  std::sort(neg.begin(), neg.end());
  std::sort(pos.begin(), pos.end());
  int ans = K > 0 ? 1000000009 : 0;
  for (int i = 0; i <= K; ++i) {
    ans = std::min({ans, neg[i] * 2 + pos[K - i], neg[i] + pos[K - i] * 2});
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,t,d,uma[100000],ans,umas[100001],ch,vs[100001];
vector<ll>v,v1;
int main(void){
  cin>>n>>k;
  for(int i=0;i<n;i++){
      cin>>t>>d;
      t--;
      if(uma[t]<d){
          if(uma[t])v.push_back(uma[t]);
          uma[t]=d;
      }
      else v.push_back(d);
  }
  for(int i=0;i<n;i++){
      if(uma[i]>0){v1.push_back(uma[i]);ch++;}
  }
  sort(v.begin(),v.end(),greater<>());
  sort(v1.begin(),v1.end(),greater<>());
  for(int i=0;i<ch;i++)umas[i+1]=umas[i]+v1[i];
  for(int i=0;i<n-ch;i++)vs[i+1]=vs[i]+v[i];
  for(ll i=1;i<=min(k,ch);i++){
      if(n-ch<k-i)continue;
      ans=max(ans,umas[i]+i*i+vs[k-i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2680
from collections import Counter

input()
s = input()
n = len(s)
try:
  x, y, z = Counter(s).values()
  print(x * y * z - sum(s[i] != s[(i + j) // 2] != s[j] != s[i]
                        for i in range(n) for j in range(i + 2, n, 2)))
except ValueError:
  print(0)


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

int main() {
  int N;
  cin >> N;
  int copy = N;
  int fN = 0;
  for (int i = 0; i < 9; i++) {
    fN = fN + copy % 10;
    copy = copy / 10;
  }
  if (N % fN == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll x;
  cin>>x;
  int i=0;
  ll sum = 0;
  while(sum < x){
    i++;
    sum += i;
  }
  cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split(" "))
    A.append(a)
    B.append(b)

ans = 0
added = 0
for a, b in zip(A[::-1], B[::-1]):
    if (a + added) % b != 0:
        ans += b - (a + added) % b
        added += b - (a + added) % b
print(ans)

Measured memory_bytes: 12624
import sys
def input():
    return sys.stdin.readline().rstrip()

moji=input()
cycle=int(input())
flont_or_back=0
flont=""
back=""
for i in range(cycle):
    line=input()
    if line[0]=="1":
        flont_or_back+=1
    else:
        fi=line[2]
        ci=line[4]
        if flont_or_back%2==0:
            if fi=="1":
                flont=ci+flont
            else:
                back+=ci
        else:
            if fi=="1":
                back+=ci
            else:
                flont=ci+flont
moji=flont+moji+back
if flont_or_back%2==0:
    print(moji)
else:
    print(moji[::-1])





Measured memory_bytes: 4588
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    char C;
    cin >> C;
    cout << (char)(C + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
//過去問演習はここ
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    long long K, A, B; cin >> K >> A >> B;
    if (B - A <= 2) {
        cout << K + 1 << endl;
    }
    else {
        long long operate = max((long long)0, (K - (A - 1)) / 2);
        cout << K + 1 - operate * 2 + B * operate - A * operate << endl;
    }
}

Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
using namespace std;


int main() {
	int N = 0;
	int A = 0;
	int B = 0;
	int n5 = 0;
	int n4 = 0;
	int n3 = 0;
	int n2 = 0;
	int n1 = 0;
	int sum = 0;
	ll allsum = 0;
	cin >> N >> A >> B;

	
	FOR(i, 1, N + 1) {
		if(i<10){
			n1 = i % 10;
			sum = n1;
			if (A <= sum && sum <= B)
				allsum += i;
		}
		else if(i<100){
			n2 = (i % 100) / 10;
			n1 = i % 10;
			sum = n2 + n1;
			if (A <= sum && sum <= B)
				allsum += i;
		}
		else if(i<1000){
			n3 = (i % 1000) / 100;
			n2 = (i % 100) / 10;
			n1 = i % 10;
			sum = n3 + n2 + n1;
			if (A <= sum && sum <= B)
				allsum += i;
		}
		else if (i<10000) {
			n4 = i / 1000;
			n3 = (i % 1000) / 100;
			n2 = (i % 100) / 10;
			n1 = i % 10;
			sum = n4 + n3 + n2 + n1;
			if (A <= sum && sum <= B)
				allsum += i;
		}
		else {
			n5 = i / 10000;
			n4 = (i % 10000) / 1000;
			n3 = (i % 1000) / 100;
			n2 = (i % 100) / 10;
			n1 = i % 10;
			sum = n5 + n4 + n3 + n2 + n1;
			if (A <= sum && sum <= B)
				allsum += i;
		}
	}
	cout << allsum;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename Pred>
long long custom_binary_search(long long low, long long high, Pred p, const bool &is_left = true){
	assert(low < high);
	while(high - low > 1){
		auto mid = low + (high - low >> 1);
		(p(mid) == is_left ? low : high) = mid;
	}
	return is_left ? low : high;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	/*string ANSWER("999");
	auto query = [&](const string &n){
		cout << "? " << n << endl;
		char resp;
		resp = (n <= ANSWER) == (stoll(n) <= stoll(ANSWER)) ? 'Y' : 'N';
		cout << resp << endl;
		return resp == 'Y';
	};*/

	auto query = [&](const string &n){
		cout << "? " << n << endl;
		char resp;
		cin >> resp;
		return resp == 'Y';
	};
	// when n>N, returns str(n)>str(N)
	// when n == N, report 'Y'
	string res(17, '9');
	int i = 0;
	while(1){
		auto pred = [&](int d){
			res[i] = '0' + d;
			return query(res);
		};
		int x = custom_binary_search(!i - 1, 9, pred, false);
		res[i] = '0' + x;
		++ i;
		if(res.substr(0, i) == string(i, '9') && !query('1' + string(i, '0')) || res.substr(0, i) != string(i, '9') && query(string(i, '9'))){
			break;
		}
	}
	cout << "! " << res.substr(0, i) << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 596
for e in iter(input,'0 0 0'):
 d=[2]*-~sum(map(int,e.split()))
 f=[]
 for _ in[0]*int(input()):
  s,t,u,v=map(int,input().split())
  if v:d[s]=d[t]=d[u]=1
  else:f+=[(s,t,u)]
 for s,t,u in f:
  if d[t]*d[u]==1:d[s]=0
  if d[u]*d[s]==1:d[t]=0
  if d[s]*d[t]==1:d[u]=0
 print(*d[1:],sep='\n')


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

using namespace std;
#define int long long
typedef long long ll;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

signed main() {
    int a, b;
    cin >> a >> b;
    if (a + b == 15) cout << "+" << endl;
    else if (a * b == 15) cout << "*" << endl;
    else cout << "x" << endl;
}



Measured memory_bytes: 256