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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {

	string S;
	cin >> S;
	int N = S.length();

	vector<pair<char,int>> v;
	for (auto p = S.begin(); p != S.end();) {
		auto q = p;
		while (q < S.end() && *p == *q) q++;
		v.push_back(P(*p, q - p));
		p = q;
	}

	int n = v.size();
	v.push_back(P('>' + '<' - v[v.size() - 1].first, 0));

	int ans = 0;
	for (int i = 0; i < n;) {
//		cerr << v[i].first << " " << v[i].second << endl;
		if (v[i].first == '<') {
			if (v[i].second < v[i + 1].second) {
				ans += v[i].second * (v[i].second - 1) / 2;
				ans += v[i+1].second * (v[i+1].second + 1) / 2;
			}
			else {
				ans += v[i].second * (v[i].second + 1) / 2;
				ans += v[i+1].second * (v[i+1].second - 1) / 2;
			}
			i += 2;
		}
		else {
			ans += v[i].second * (v[i].second+1)/2;
			i++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6264
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var sNum = NM[0];
            var cNum = NM[1];
            var ans = 0L;
            if (2 * sNum <= cNum)
            {
                ans = sNum + (cNum - 2 * sNum) / 4;
            }
            else
            {
                ans = cNum / 2;
            }
            WriteLine(ans);
            Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		if (N <= 111) {
			System.out.println(111);
		} else if (N <= 222) {
			System.out.println(222);
		} else if (N <= 333) {
			System.out.println(333);
		} else if (N <= 444) {
			System.out.println(444);
		} else if (N <= 555) {
			System.out.println(555);
		} else if (N <= 666) {
			System.out.println(666);
		} else if (N <= 777) {
			System.out.println(777);
		} else if (N <= 888) {
			System.out.println(888);
		} else if (N <= 999) {
			System.out.println(999);
		} 
	}
}


Measured memory_bytes: 23764
n = int(input())
XY = []
ans = 0

for i in range(n):
    z = []
    
    for j in range(int(input())):
        x,y = map(int,input().split())
        z.append([x,y])
        
    XY.append(z)
        
for i in range(2**n):
    honest = 0
    mujunn = 0
    
    for j in range(n):
        if (i>>j) & 1:
            honest += 1
            
            for k in XY[j]:
                x = k[0] - 1
                y = k[1]
                
                if (i>>x)&1 != y:
                    mujunn = 1
                    break
                    
        if mujunn == 1:
            break
                
    if mujunn == 0:
        ans = max(ans,honest)
        
print(ans)

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

int main(){
	int n,q;
	int count =0;
	
	vector<int> S;
	vector<int> T;
	
	cin>>n;
	int tmp;
	for(int i=0;i<n;i++){
		cin>>tmp;
		S.push_back(tmp);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>tmp;
		for(int j=0;j<n;j++){
			if(tmp==S[j]){
				count++;
				break;
			}
		}
	}
	
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1320
from itertools import accumulate
import copy

S=input()
ANS=[0]
for s in S:
    if s=="0":
        ANS.append(-1)
    else:
        ANS.append(1)
SUM=list(accumulate(ANS))
MIN=[SUM[-1]]
for s in SUM[::-1][1:]:
    MIN.append(min(MIN[-1],s))
MIN.reverse()
MX=min(MIN)

ANS2=copy.deepcopy(ANS)
sa=0
for i in range(len(S)):
    if S[i]=="?":
        if MIN[i+1]-MX-sa>=2:
            ANS2[i+1]=-1
            sa+=2

ANS3=copy.deepcopy(ANS)
sa=0
MX-=1
for i in range(len(S)):
    if S[i]=="?":
        if MIN[i+1]-MX-sa>=2:
            ANS3[i+1]=-1
            sa+=2

S2=list(accumulate(ANS2))
S3=list(accumulate(ANS3))

print(min(max(S2)-min(S2),max(S3)-min(S3)))

Measured memory_bytes: 166716
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h=0;
	int n=0;
	int sum=0;
	cin>>h>>n;
	vector<int> A(n);
	for(int i=0;i<n;i++)
	{
		cin>>A[i];
		sum+=A[i];
	}
	if(sum>=h)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,A,B;cin>>N>>A>>B;
  string S;cin>>S;
  int dome=0,abr=0;
  REP(i,0,S.size()){
    if(S.at(i)=='a'&&dome+abr<A+B){
      print("Yes");
      dome++;
    }
    else if(S.at(i)=='b'&&dome+abr<A+B&&abr<B){
      print("Yes");
      abr++;
    }
    else{
      print("No");
    }
  }

}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str, op, replica, rev;
  int q, a, b;
  cin >> str >> q;
  for (size_t i = 0; i < q; i++) {
    cin >> op >> a >> b;

    if (op == "replace") {
      cin >> replica;
      str.replace(a, b - a + 1, replica);
    } else if (op == "reverse") {
      rev = str.substr(a, b - a + 1);
      reverse(rev.begin(), rev.end());
      str.replace(a, b - a + 1, rev);

    } else if (op == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
}



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

using namespace std;

int b,a[1000],n,cnt=1;
double ans;

int main () {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		ans += double(1 / double(a[i]));
	}
	cout << fixed << setprecision(7) << double(1 / ans);
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main()
{
    input! {
    n:i32,
    k:i32,
    }

    let mut ans = 0.0;
    for i in 1..=n {
        let mut m = 1.0 / n as f64;
        let mut x = i;
        while x < k {
            x *= 2;
            m *= 0.5;
        }
        ans += m;
    }

    println!("{:.12}", ans);
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    if(n==1){
        cout<<max(arr[0][0],max(arr[0][1],arr[0][2]))<<endl;
        return 0;
    }
    int dp[n][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++){
        dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    
    
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 5872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n;
      cin >> n;
      int a[n];
      rep(i,n)cin >> a[i];
      int m;
      cin >> m;
      int b[m];
      rep(i,m)cin >> b[i];
      sort(a,a+n);
      sort(b,b+m);
      int count=0;
      rep(i,m){
       int j=upper_bound(a,a+n,b[i])-lower_bound(a,a+n,b[i]);
        if(j>0)count++;
      }
      cout << count << endl;
      return 0;}


Measured memory_bytes: 3720
n = int(input())
sum = 0
p = [int(e) for e in input().split()]
for i in range(n-2):
    if p[i+1] > p[i] and p[i+1] < p[i+2]:
        sum+=1
    elif p[i+1] < p[i] and p[i+1] > p[i+2]:
        sum+=1

print(sum)

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

int main(){
	long long n,m;
	cin>>n>>m;
	long long inf=1e9+7;

	if(abs(n-m)>1){
		cout<<0<<endl;
		return 0;
	}

	long long ans=1;

	for(long long i=1;i<=n;i++){
		ans=(ans*i)%inf;
	}

	for(long long i=1;i<=m;i++){
		ans=(ans*i)%inf;
	}

	cout<<(n==m ? (ans*2)%inf : ans)<<endl;//(条件)?真の処理:偽の処理; 
	return 0;
}


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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define bk back
#define ed endl
#define en cout << endl
#define wl while
#define mod 1000000007
#define f(i, a, b) for(ll i = a; i < b; i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
const int INF = 1e9 + 5;

using namespace std;

int main()
{
    FAST;
    int n; cin >> n;
    vector<int> h;
    for(int i = 0; i < n; i++)
    {
        int val;
        cin >> val;
        h.pb(val);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j: {i + 1, i + 2})
        {
            if(j < n)
            {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }

    }

    cout << dp[n - 1] << ed;

    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

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

    char c;
    cin >> c;
    cout << (c == 'A' ? 'T' : c == 'T' ? 'A' : c == 'G' ? 'C' : 'G') << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int count = 0;

		//処理
		for(int i = a; i <= b; i++) {
			if(c % i == 0) {
				count++;
			}
		}

		//出力
		System.out.println(count);

	}

}



Measured memory_bytes: 26320
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#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 pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  ll ans=0;
  vll a(26);
  rep(i,sz(s)){
    a[s[i]-'a']++;
  }
  rep(i,26){
    ans+=a[i]*(a[i]-1)/2;
  }
  COUT(sz(s)*(sz(s)-1)/2-ans+1);
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	set<string> st={"AKIHABARA", "KIHABARA", "AKIHBARA", "KIHBARA", "AKIHABRA", "KIHABRA", "AKIHBRA", "KIHBRA", "AKIHABAR", "KIHABAR", "AKIHBAR", "KIHBAR", "AKIHABR", "KIHABR", "AKIHBR", "KIHBR"};
	string s; cin>>s;
	cout<<(st.count(s)?"YES":"NO")<<"\n";
	return 0;
}

Measured memory_bytes: 256
f=lambda:map(int,input().split())
n,m=f()
g=[[0]*n for _ in range(n)]
for i in range(m):
  a,b=f(); g[a-1][b-1]=g[b-1][a-1]=1
import itertools as it
c=0
for t in it.permutations(range(1,n)):
  p,d=0,1
  for q in t: d*=g[p][q]; p=q
  c+=d
print(c)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ss second
#define ff first
#define pb push_back
using namespace std;

const int N = 1e6 + 6;
int x,n;
int A[N];
int answer=0;
int fix[N];
int main(){

        cin >> n;
        for(int i = 1; i <=n; i++ ){
                cin >> A[i];
                fix[A[i]]++;
        }

        for(int i = 1; i <= n; i++){
                fix[A[i]]--;
                bool ok = false;
                for(ll j = 1; j*j <= A[i]; j++){
                        if(A[i]%j) continue;
                        if(fix[j] || fix[A[i]/j]) ok = true;
                }
                fix[A[i]]++;

                if(!ok){
                        answer++;
                }
        }

        cout << answer << endl;
}


Measured memory_bytes: 8144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	string s;cin>>s;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define N 100
using namespace std;

int main(){
  int m,n,a[N][N],f,ans=0;
  cin>>m>>n;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++){
      cin>>a[i][j];
      if(!i&&(j&&j!=n-1))
	a[i][j]=!a[i][j];	
      if(i&&(!j||j==n-1))
	a[i][j]=!a[i][j];
    }
  for(int i=0;i<m;i++){
    f=0;
    for(int j=0;j<n;j++){
      if(a[i][j])ans++;
      if(!a[i][j])f=1;
    }
    if(n==1)continue;
    if(f)ans++;
    else ans--;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define N (5000+10)
#define next Next
#define inf (0x3f3f3f3f)
using namespace std;
const int maxn=50000+10;
int to[maxn<<1],next[maxn<<1],head[N<<1],v[maxn<<1],w[maxn<<1];
int ans=0,e=1,dis[N],vis[N];
int a[50][50][2];
inline void add(int x,int y,int z,int zz){
    to[++e]=y;
    next[e]=head[x];
    head[x]=e;
    w[e]=z;
    v[e]=zz;
}
int n,m,s,t,x,y,z,zz;
inline bool spfa(){
    queue<int> q;
    memset(vis,0,sizeof(vis));
    memset(dis,inf,sizeof(dis));
    dis[vis[s]=s]=0;
    q.push(s);
    while(!q.empty()){
        int k=q.front();
        q.pop();
        for(register int i=head[k];i;i=next[i]){
            if(w[i]&&dis[to[i]]>dis[k]+v[i]){
                dis[to[i]]=dis[k]+v[i];
                if(!vis[to[i]])
                    q.push(vis[to[i]]=to[i]);
            }
        }
        vis[k]=0;
    }
    return dis[t]<inf;
}
inline int dfs(int x,int flow){
    vis[x]=1;
	if(x==t||!flow)
        return vis[x];
    for(register int i=head[x];i;i=next[i])
        if(!vis[to[i]]&&w[i]&&dis[to[i]]==dis[x]+v[i]){
            int ovo=dfs(to[i],min(flow,w[i]));
            if(ovo>0){
                ans+=v[i]*ovo;
                w[i]-=ovo;
                w[i^1]+=ovo;
                return ovo;
            }
        }
    return 0;
}
inline int dinic(){
    int flow=0;
    while(spfa()){
        vis[t]=1;
        while(vis[t]){
            memset(vis,0,sizeof(vis));
            flow+=dfs(s,inf);
        }
    }
    return flow;
}

int main(){
  //  freopen("1559.in","r",stdin);
  //  freopen("1559.out","w",stdout);
	int aa,bb,cc,dd;
	cin>>aa>>bb>>cc>>dd;
	printf("%d\n",min(aa,bb)+min(cc,dd));
	return 0;
    scanf("%d",&n);
	for(int k=0;k<2;++k)
		for(register int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				scanf("%d",&a[i][j][k]);
	s=n*2+1;t=s+1;
	for(int i=1;i<=n;++i){
		add(s,i,1,0);
		add(i,s,0,0);
		add(i+n,t,1,0);
		add(t,i+n,0,0);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			add(i,j+n,1,-a[i][j][0]*a[j][i][1]);
			add(j+n,i,0,a[i][j][0]*a[j][i][1]);
		}
    dinic();
    printf("%d",-ans);
    return 0;
}




Measured memory_bytes: 764
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

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

   int k;cin >> k;
   long long ans = 0;
   for(int a = 1;a <= k;a++){
        for(int b = 1;b <= k;b++){
            for(int c = 1;c <= k;c++){
                ans += gcd(gcd(a,b),c);
            }
        }
   } 
   cout << ans << '\n';

}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

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

  int ans=min(a*n,b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;
long ans[100005];

int main(){
    std::cin >> s;
    long even = 0, odd = 0;
    for(int i = 0; i < s.length()-1; i++){
        if(s[i] == 'R'){
            std::swap(even, odd);
            even++;
        }
        if(s[i+1] == 'L'){
            ans[i] += even;
            ans[i+1] += odd;
            even = 0, odd = 0;
        }
    }
    even = 0, odd = 0;
    for(int i = s.length()-1; i > 0; i--){
        if(s[i] == 'L'){
            std::swap(even, odd);
            even++;
        }
        if(s[i-1] == 'R'){
            ans[i] += even;
            ans[i-1] += odd;
            even = 0, odd = 0;
        }
    }
    for(int i = 0; i < s.length(); i++){
        printf("%ld ", ans[i]);
    }
    printf("\n");
}


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

C_list = [list(map(int, input().split())) for i in range(N)]
import itertools

targets = list(itertools.product([0, 1], repeat=N))
#print(targets)
answer = 10 ** 9
for target in targets:
    result = [0] * (M + 1)
    for i, t in enumerate(target):
        if t == 1:
            for j in range(M + 1):
                result[j] += C_list[i][j]
        #print(result)
    if min(result[1:]) >= X:
        #print(result)
        answer = min(answer,result[0])
if answer == 10 ** 9:
    print(-1)
else:
    print(answer)

Measured memory_bytes: 9628
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m;
inline ll read(){
    ll s = 0, w = 1;
    char ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
    for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

inline void work(){
    n = read(), m = read();
    if (n == 1 || m == 1) puts("1");
    else printf("%lld\n", (n * m + 1) / 2);
}

int main(){
    work();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

#define maxn 100005
int n,res[maxn],pos[maxn];
char s[maxn];
vector <int> a;
int main(){
  scanf("%s",s + 1);
  n = strlen(s + 1);
  int cnt = 0;
  for(int i = 1;i <= n;i++){
    if(i == 1) cnt = 1;
    else if(s[i] == s[i - 1]) cnt++;
    else{
      a.push_back(cnt);
      cnt = 1;
    }
  }
  a.push_back(cnt);
  for(int i = 0;i < (int)a.size();i++){
    if(i == 0) pos[i] = a[i];
    else pos[i] = pos[i - 1] + a[i];
  }
  for(int i = 0;i < (int)a.size();i += 2){
    res[pos[i]] += (a[i] + 1) / 2;
    res[pos[i] + 1] += a[i] / 2;
  }
  for(int i = 1;i < (int)a.size();i += 2){
    res[pos[i - 1] + 1] += (a[i] + 1) / 2;
    res[pos[i - 1]] += a[i] / 2;
  }
  for(int i = 1;i <= n;i++) printf("%d%c",res[i],i == n ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  long long a = M * 1900 + (N - M) * 100;
  a <<= M;
  cout << a << '\n';
  return 0;
}


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

inline int spt(int a){
	if (a == 0) return 1;
	a--;
	a |= a >> 1;
	a |= a >> 2;
	a |= a >> 4;
	a |= a >> 8;
	a |= a >> 16;
	a++;
	return a;
}

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

	int n, k, m;
	cin >> n >> k;
	m = spt(k);
	long long num = 0, den = ((long long) n)*((long long) m);
	for (int i = 1; i <= n; i++){
		if (k % i) num += m/spt((k/i) + 1);
		else num += m/spt(k/i);
	}
	cout << ((double) num)/den << '\n';
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<char> s(n);
    for(int i=0;i<n;i++){
        cin >> s.at(i);
    }
    sort(s.begin(),s.end());
    int cnt=1;
    for(int i=0;i<n-1;i++){
        if(s.at(i) != s.at(i+1)){
            cnt++;
        }
    }
    
    cout << (cnt==3?"Three":"Four") << endl;
}


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

signed main(){
    string s; cin>>s;
    int N=s.size();

    for(int i=0;i<N;i++){
        if(i%2==0 and s[i]=='L'){
            cout<<"No"<<endl;
            return 0;
        }
        if(i%2==1 and s[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >>K;
  if (A+B<K)
    cout << 2*A+B-K << endl;
  else
    cout << min(K, A) << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)
 
int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(s.size()>a)
	{
		forr(i,0,a)
			cout<<s[i];
		cout<<"...";
	}
	else
		cout<<s;
	
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in range(1, 4):
    D = 0
    for i in range(n):
        D += abs(x[i] - y[i]) ** p
    D = D ** (1/p)
    print(D)
D = 0
for i in range(n):
    tmp = abs(x[i] - y[i])
    if D < tmp:
        D = tmp
print(D)


Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <string>
          
using namespace std;
          
int main() {
int a,b;
string op;
while(true){
cin >> a >> op >> b;
if(op == "+")
cout << a+b << endl;
else if(op == "-")
cout << a-b << endl;
else if(op == "*")
cout << a*b << endl;
else if(op == "/")
cout << a/b << endl;
else return 0;
}
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;

int main() {
	map<string, int> reg;
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		string str; cin >> str;
		reg[str] = 0;
	}
	int k = 0;
	int M; cin >> M;
	for (int i = 0; i < M; ++i) {
		string str; cin >> str;
		if (reg.find(str) != reg.end()) {
			if (k == 0) {
				printf("Opened by %s\n", str.c_str());
				k = 1;
			}
			else {
				printf("Closed by %s\n", str.c_str());
				k = 0;
			}
		}
		else printf("Unknown %s\n", str.c_str());
	}
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N,M,k;
    cin >> N >> M;
    vector<vector<int>> table(M);
    vector<int> ans;
    REP(i,0,M){
        cin >> k;
        REP(j,0,k){
            int cur;
            cin >> cur;
            table[i].push_back(cur);
        }
    }
    REP(i,0,M){
        cin >> k;
        ans.push_back(k);
    }


    int cnt=0;
    REP(i,0,1<<N){
        bitset<10> b1(i);
        bool flag = true;
        REP(j,0,M){
            int in_cnt=0;
            for(auto a:table[j]){
                if(b1[a-1]==1) in_cnt++;
            }
            if(in_cnt%2!=ans[j]) flag=false;
        }
        if(flag) cnt++;
    }
    P(cnt);
}

Measured memory_bytes: 256
N, Y = map(int,input().split())
for i in range(N+1):
  for j in range(N+1):
    if Y == 10000*i + 5000*j + 1000*(N-i-j) and N-i-j >= 0:
      print(i," ",j," ",N-i-j)
      break
  else:
    continue
  break
else:
  print("-1 -1 -1")

Measured memory_bytes: 3060
n, k = map(int, input().split())
A = list(map(int, input().split()))

k_bin = "{:040b}".format(k)
A_bin = list(map(lambda x: '{:040b}'.format(x), A))
X = ''
first = 1
for i, col in enumerate(zip(*A_bin)):
    if k_bin[i] == '0' and first:
        X += '0'
        continue
    if first:
        zero_cnt = col.count('0')
        one_cnt = n-zero_cnt
        if one_cnt < zero_cnt:
            X += '1'
        else:
            first = 0
            X += '0'
        continue

    zero_cnt = col.count('0')
    one_cnt = n-zero_cnt
    if one_cnt < zero_cnt:
        X += '1'
    else:
        X += '0'

X = int(X, 2)

ans = 0
for a in A:
    ans += X ^ a
print(ans)


Measured memory_bytes: 26924
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

string s;
string t;
void replace(int i){
    for(int k=0;k<t.size();k++){
    s[i+k]=t[k];
    }
}
int main(){

cin >>s;
cin >> t;

int l=0;
int Key=0;
for(int i=s.size()-t.size();i>=0;i--){
        for(int k=0;k<t.size();k++){
            if(s[i+k]==t[k]|| s[i+k]=='?'){
                Key++;
            }
        }
    if(Key==t.size()){
        replace(i);
        break;
    }
    Key=0;
}
for(int i=0;i<s.size();i++){
    if(s[i]=='?'){
        s[i]='a';
    }
}
if(Key==0){
    cout<<"UNRESTORABLE"<<endl;
}
else{
    cout<<s<<endl;
}
    

 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<unordered_set>
#include<limits.h>
using namespace std;

typedef unsigned long long ll;







int main(){
    int n,m;
    vector<string>v1,v2;
    cin>>n>>m;
    v1.resize(n);
    string st;
    for(int i=0;i<n;i++){
        cin>>st;
        v1[i]=st;
    }
    
    for(int i=0;i<m;i++){
        cin>>st;
        v2.push_back(st);
    }
    for(int i=0;i+m<=n;i++){
        for(int j=0;j+m<=n;j++){
            bool ok=true;
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(v1[i+k][j+l]!=v2[k][l]){
                        ok=false;
                        break;
                    }
                }
            }
            if(ok){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[][] card = new int[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    card[i][j] = in.nextInt();
                }
            }

            int n = in.nextInt();
            List<Integer> l = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                l.add(in.nextInt());
            }

            int[][] trans = new int[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    trans[j][i] = card[i][j];
                }
            }

            int[] lDiagonally = {card[0][0], card[1][1], card[2][2]};
            int[] rDiagonally = {card[2][0], card[1][1], card[0][2]};

            if (checkLine(card[0], l) || checkLine(card[1], l) || checkLine(card[2], l) || checkLine(trans[0], l) || checkLine(trans[1], l) || checkLine(trans[2], l) || checkLine(lDiagonally, l) || checkLine(rDiagonally, l)) {
                out.append("Yes");
            } else {
                out.append("No");
            }
        }

        private boolean checkLine(int[] l, List<Integer> r) {
            for (int i : l) {
                if (!r.contains(i)) {
                    return false;
                }
            }
            return true;
        }

    }
}



Measured memory_bytes: 21204
local mmi = math.min
local inf = 0
local t = {}
for i = 1, 400 * 400 do t[i] = 0 end

local n, ma, mb = io.read("*n", "*n", "*n")
for i = 1, n do
  local a, b, c = io.read("*n", "*n", "*n")
  for ia = 400, 1, -1 do
    for ib = 400, 1, -1 do
      local src = (ia - 1) * 400 + ib
      if 0 < t[src] then
        local dst = (ia + a - 1) * 400 + ib + b
        if t[dst] == 0 then
          t[dst] = t[src] + c
        else
          t[dst] = mmi(t[dst], t[src] + c)
        end
      end
    end
  end
  local first_dst = (a - 1) * 400 + b
  if t[first_dst] == 0 then
    t[first_dst] = c
  else
    t[first_dst] = mmi(t[first_dst], c)
  end
end

local ret = -1
for ia = 1, 400 do
  if ia % ma == 0 then
    ib = math.floor(ia * mb / ma)
    if ib <= 400 then
      local c = t[(ia - 1) * 400 + ib]
      if 0 < c then
        if ret < 0 then
          ret = c
        else
          ret = mmi(ret, c)
        end
      end
    end
  end
end
print(ret)


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

vector< int> E[N];

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int n, m;
	cin >> n >> m;

	vector< int> el(n);
	for (int i = 0; i < n; i++) {
		cin >> el[i];
	}

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		E[x].push_back(y);
		E[y].push_back(x);
	}

	int res = 0;
	for (int i = 0; i < n; i++) {
		int ok = 1;
		for (int x : E[i]) {
			if (el[x] >= el[i]) {
				ok = 0;
			}
		}
		res += ok;
	}

	cout << res << endl;
}

Measured memory_bytes: 8780
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
double x;
bool is_integer(double x){
  return floor(x)==x;
}

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

  cin >> x;
  for(ll i = -200; i <= 200; i++) {
    for(ll j = -200; j <= 200; j++) {
      if(pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}


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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int> xs(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> xs[i];
  }
  sort(xs.begin(), xs.end());

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += min(xs[2 * i], xs[2 * i + 1]);
  }
  cout << ans << endl;
}

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

typedef long long ll;

int n;
int a;

int main()
{
	ll tot = 1, odd = 1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		tot *= 3ll;
		if (a % 2 == 0) odd *= 2ll;
	}
	tot -= odd;
	cout << tot << endl;
	return 0;
}

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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var a = long.Parse(s[0]);
            var b = long.Parse(s[2]);

            if(s[1].Equals("+")){
                Console.WriteLine(a + b);
            }else{
                Console.WriteLine(a - b);
            }
        }
    }
}


Measured memory_bytes: 13140
// 🐋💭  Marks
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}
// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

func main() {
    let nk = readInts()
    let (n, k) = (nk[0], nk[1])
    let aryScore = readInts()
    //___________________________ここまで入力
    var left = 0
    for i in k..<n {
        //print(aryScore[left],aryScore[i])
        print(aryScore[left] < aryScore[i] ? "Yes":"No")
        left += 1
    }
}
main()



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

int main(){
    int n;
    cin >> n;
    vector<long long> sequence(n);
    for (int i=0;i<n;i++){
        cin >> sequence[i];
    }
    long long acc_1 = 0;
    long long manipulation_1 = 0;
    long long acc_2 = 0;
    long long manipulation_2 = 0;

    for (int i=0;i<sequence.size();i++){
        acc_1 += sequence[i];
        if (i % 2 == 0){
            if (acc_1 >= 0){
                manipulation_1 += acc_1 + 1;
                acc_1 = -1;
            }
        } else {
            if (acc_1 <= 0){
                manipulation_1 += 1 - acc_1;
                acc_1 = 1;
            }
        }
    }
    for (int i=0;i<sequence.size();i++){
        acc_2 += sequence[i];
        if (i % 2 == 0){
            if (acc_2 <= 0){
                manipulation_2 += 1 - acc_2;
                acc_2 = 1;
        }
        } else {
            if (acc_2 >= 0){
                manipulation_2 += acc_2 + 1;
                acc_2 = -1;
            }
        }
    }
    cout << min(manipulation_1, manipulation_2) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n, m, v, p;
llint a[100005];
llint sum[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> v >> p;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		if(i <= p){
			ans++;
			continue;
		}
		if(a[p] > a[i] + m) continue;
		if(p >= v){
			ans++;
			continue;
		}
		llint s = (n-p+1-1)*(a[i]+m);
		s -= (n-i)*a[i];
		s -= sum[i-1]-sum[p-1];
		if(s / (v-p) >= m) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    map<string,int> m;

    rep(i,N){
        string t;cin >> t;
        m[t]++;
    }

    cout << m.size() << endl;
}

Measured memory_bytes: 19256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,s[1000];
void puch(int x)
{
s[++top]=x;
}
int  pop()
{
top--;
return s[top+1];
}
int main()
{
    int a,b;
    top=0;
    char c[100];
    while(scanf("%s",c)!=EOF)
    {
        if(c[0]=='+'){
            a=pop();
            b=pop();
            puch(a+b);
        }else if(c[0]=='-'){
            a=pop();
            b=pop();
            puch(b-a);

        }else if(c[0]=='*'){
            a=pop();
            b=pop();
            puch(a*b);
        }else{
        puch(atoi(c));
        }
    }
    printf("%d\n",pop());
    return 0;

}

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

int main() {
  string a, b;
  cin >> a >> b;
  int ai, bi;
  ai = atoi(a.c_str());
  bi = atoi(b.c_str());
  string aa, bb;
  rep(i, ai) {
    bb += b;
  }
  rep(i, bi) {
    aa += a;
  }
  string ans = aa < bb ? aa : bb;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a,b,d,c,e;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	c=c+e;
	d=d+e;
if(a>=c&&c>0&&d>0){
		if(b>=d){printf("Yes\n");
		}else{printf("No\n");}
	}else{printf("No\n");}
return 0;
}


Measured memory_bytes: 2684
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int main(){
	int N=0;
	scanf("%d",&N);
	printf("%d\n",N/3);
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let S = rl().chars().vec();

    let mut r = None;
    for i in 0..S.len() {
        if i + 1 < S.len() && S[i] == S[i + 1] {
            r = Some((i + 1, i + 2));
            break;
        }

        if i + 2 < S.len() && S[i] == S[i + 2] {
            r = Some((i + 1, i + 3));
            break;
        }
    }

    match r {
        Some((l, r)) => println!("{} {}", l, r),
        None => println!("-1 -1"),
    }
    return;
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(--t >= 0){
        int n, k;
        cin >> n >> k;

        vector<int> pos(n);
        for(int i=0; i<n; ++i)
            cin >> pos[i];
        if(k >= n){
            cout << 0 << endl;
            continue;
        }
        sort(pos.begin(), pos.end());

        vector<long long> dist(n-1);
        for(int i=1; i<n; ++i)
            dist[i-1] = pos[i] - pos[i-1];
        sort(dist.begin(), dist.end());

        long long ret = accumulate(dist.begin(), dist.end()-k+1, 0);
        cout << ret << endl;
    }
}

Measured memory_bytes: 2184