akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string S;
    int i = S.size();
    int j = 1;
    cin>>S;
    while(j<=S.size())
    {
        if(S[j-1]=='R'&&j%2==0)
            break;
        if(S[j-1]=='L'&&j%2==1)
            break;
        j++;
    }
    if(j>S.size())
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=1e6+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int n,cnt[N],g=0;
vector<int> a;
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    int x;
    cin>>x;
    g=__gcd(g,x);
    if(x==1) continue;
    a.push_back(x);
    cnt[x]++;
  }
  if(a.size()==0)
  {
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  int flag=0;
  for(int i=2;i<N;i++)
  {
    if(cnt[i]>1)
    {
      flag=1;
      break;
    }
  }
  if(flag)
  {
    if(g==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
  }
  else
  {
    set<int> s;
    for(int i=0;i<a.size();i++) s.insert(a[i]);
    auto it1=s.end();
    it1--;
    int mx=(*it1);
    for(int i=2;i<=mx;i++)
    {
      int cnt=0;
      for(int j=i;j<=mx;j+=i)
      {
        auto it=s.find(j);
        if(it!=s.end())
        {
          cnt++;
        }
        if(cnt>1)
        {
          if(g==1) cout<<"setwise coprime"<<endl;
          else cout<<"not coprime"<<endl;
          return 0;
        }
      }
    }
    cout<<"pairwise coprime"<<endl;
  }
  return 0;
}


Measured memory_bytes: 57820
//code by lynmisakura.wish to be accepted!
#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>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll> > vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
const int MaxN=10000010,mod=998244353;
int fac[MaxN*2],ifac[MaxN*2];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int C(int n,int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

map<pair<string,string>,long long> m;

int main(void){
    
    ll n;cin >> n;
    string s;cin >> s;
    for(int i = 0;i < (1 << n);i++){
        string p,q;p = q = "";
        for(int j = 0;j < n;j++){
            if(i >> j & 1)p += (char)s[n+j];
            else q += (char)s[n+j];
        }
        reverse(all(p));
        reverse(all(q));
        m[mp(p,q)]++;
    }
    /*for(auto i : m){
        cout << i.ff.ff << " " << i.ff.ss << " " << i.ss << endl;
    }*/
    long long ans = 0;
    for(int i = 0;i < (1 << n);i++){
        string p,q;p = q = "";
        for(int j = 0;j < n;j++){
            if(i >> j & 1)p += (char)s[j];
            else q += (char)s[j];
        }
        ans += m[mp(p,q)];
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 87040
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>

int main(){

        char original[3][3],nova[1][3];

        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                scanf(" %c",&original[i][j]);
                if(i==j){
                    printf("%c",original[i][j]);
                }
            }
        }
        puts("");


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

vi a;

void maxHeapify(int i){
	int l=2*i+1,r=2*i+2,largest;
	if(l<a.size() && a[l]>a[i]) largest=l;
	else largest=i;
	if(r<a.size() && a[r]>a[largest]) largest=r;
	if(largest!=i){
		swap(a[i],a[largest]);
		maxHeapify(largest);
	}
}
void buildMaxHeap(){
	for(int i=a.size()/2;i>=0;i--){
		maxHeapify(i);
	}
}

int main(){
	int n,t;
	cin>>n;
	rep(i,0,n){
		cin>>t;
		a.pb(t);
	}
	buildMaxHeap();
	rep(i,0,n){
		cout<<" "<<a[i];
	}
	cout<<endl;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,g = 0,a[200010],ans[200010];
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		g ^= a[i];
	}
	for(int i = 0;i < n;i++) printf("%lld%c",g ^ a[i]," \n"[i == n - 1]);
}

Measured memory_bytes: 5140
import collections
N=int(input())
W=[""]*N
for i in range(N):
  W[i]=input()
c=collections.Counter(W)
if len(c)!=N :
  print("No")
  exit()
for i in range(N-1):
  if W[i][-1] != W[i+1][0] :
    print("No")
    exit()
print("Yes")

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

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  int n = S.size();
  for (int i = 0; i < n; i++) {
    if (S.at(i) != T.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3628
# -*= coding: utf-8 -*-

A, B = map(int, input().split())
x = 25 * A // 2

for x in range(B * 10 + 0, B * 10 + 10, 1):
  if round(x * 8 // 100) == A:
    print(x)
    exit()
print('-1')

Measured memory_bytes: 61796
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int main(void) {
  string S;
  cin >> S;
  S.resize(S.size() - 8);
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a,i,n;
	bool b=true;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a;
		if(a%2==0){
			if((a%3!=0)&&(a%5!=0)){
				b=false;
				break;
			}
		}
	}
	if(b==true) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define psi pair<string,int>
#define pipsi pair<int, psi>

vector<pipsi > V;

bool mySort(pipsi a, pipsi b){
	if(a.second.first<b.second.first)
      	return true;
 	else if(a.second.first>b.second.first)
      	return false;
  	else
      	return a.second.second>b.second.second;
}

main(){
	int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string city;
        int rating;
        cin>>city>>rating;
        V.push_back({i,{city,rating}});
    }
    sort(V.begin(),V.end(),mySort);
    for(auto x: V){
        cout<<x.first<<"\n";
    }
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
    FastRead
    deque<char>D;
    string str;
    cin >> str;
    int q;
    cin >> q;

    for(int i = 0;i < str.size();i++){
        D.push_back(str[i]);
    }
    bool x = 0;
    while(q--){
        int t;cin >> t;
        if(t == 1){
            x = 1 - x;
        }else{
            int f;cin >> f;
            char ch;cin >> ch;
            f--;
            if((f ^ x) != 0)D.push_back(ch);
            else D.push_front(ch);
        }
//        for(char i : D)cout << i;
//        cout << "\n";
    }
    if(x)REV(D);
    for(char i : D)cout << i;
    cout << "\n";
}


Measured memory_bytes: 976
#include "bits/stdc++.h"
using namespace std;

bool kansuu(int num, int keta, pair<int, char> sc)
{
	string str;
	str = to_string(num);

	if (str.size() != keta) {
		return false;
	}
	if (str[sc.first - 1] == sc.second) {
		return true;
	}
	return false;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, char>> sc(m);
	for (int i = 0; i < m; i++) {
		int s_in;
		char c_in;
		cin >> s_in >> c_in;
		sc.at(i) = make_pair(s_in, c_in);
	}

	int ans = 1000;
	for (int num = 0; num < 1000; num++) {
		bool flag = true;
		for (auto sc_ele : sc) {
			flag = kansuu(num, n, sc_ele);
			if (flag == false) {
				break;
			}
		}
		if (flag == true) {
			ans = num;
			break;
		}
	}

	if (ans == 1000) {
		ans = -1;
	}

	if (m == 0) {
		if (n == 1) {
			ans = 0;
		}
		if (n == 2) {
			ans = 10;
		}
		if (n == 3) {
			ans = 100;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 101024;

int x[MAXN];

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

    int sp = x[0] - 1;
    int stock = 1;
    ll res = 1;
    ll mod = pow(10, 9) + 7;
    for(int i = 1; i < n; ++i) {
        ++stock;
        sp += x[i] - x[i-1] - 1;
        if(stock > sp + 1) {
            res = (res * stock) % mod;
            --stock;
            ++sp;
        }
    }

    for(int i = 0; i < stock; ++i) {
        res = (res * (stock - i)) % mod;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
N,X,M=gets.chomp.split(" ").map(&:to_i)
MEMO=Array.new(M,nil)
ARRAY=[X]
ret=X
n=1
x=X
while n < N do
    r=x*x%M
    if MEMO[r] != nil
        d=ret-ARRAY[MEMO[r]-1]
        m=(N-n)/(n-MEMO[r])
        l=(N-n)%(n-MEMO[r])
        ret+=(d*m + ARRAY[MEMO[r]-1+l]-ARRAY[MEMO[r]-1])
        break
    else
        MEMO[r]=n
        ret+=r
        ARRAY.push(ret)
    end
    n+=1
    x=r
end
puts ret


Measured memory_bytes: 15632
#include <iostream>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <algorithm>
#include <string>

using namespace std;
int main() {
    long long N; cin>>N;
    vector<unsigned int> xors(N);
    for (auto& n : xors) cin>>n;
    int allxor = 0;
    for (auto n : xors) allxor = allxor ^ n;
    for (auto n : xors) {
        cout<< (allxor ^ n) << " ";
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 4040
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX=500005;
int tree[MAX];int H;
void maxHeapify(int i){
	int lgst=i;
	if(2*i<=H&&tree[lgst]<tree[2*i])lgst=2*i;
	if(2*i+1<=H&&tree[lgst]<tree[2*i+1])lgst=2*i+1;
	if(lgst==i)return;
	swap(tree[lgst],tree[i]);
	maxHeapify(lgst);
}
void buildMaxHeap(){
	for(int i=H/2;i>0;i--){
		maxHeapify(i);
	}
}
int main(){
	memset(tree,-1,sizeof(tree));
	cin>>H;
	for(int i=1;i<=H;i++){
		cin>>tree[i];
	}
	buildMaxHeap();
	for(int i=1;i<=H;i++){
		printf(" %d",tree[i]);
	}
	putchar('\n');
	return 0;
}


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

int mod(const int x, const int m) { return x % m >= 0 ? x % m : x % m + m; }
int fld(const int x, const int y) { return (x - mod(x, y)) / y; }

int main()
{
    ios::sync_with_stdio(false);

    int N, L, T; cin >> N >> L >> T;

    auto crosses = 0;
    auto positions = vector<int>();
    for (auto i = 0; i < N; i++)
    {
        int X, W; cin >> X >> W;
        const auto delta = W == 1 ? T : -T;
        positions.push_back(mod(X+delta, L));
        crosses += fld(X+delta, L);
        crosses = mod(crosses, N);
    }
    sort(begin(positions), end(positions));
    rotate(begin(positions), begin(positions) + crosses, end(positions));
    for (const auto x : positions) cout << x << "\n";
}


Measured memory_bytes: 1784
#include<stdio.h>
long long MAX(long long a,long long b){return a<b?b:a;}
int main(){
  long long a,b,c,d,m=-1e18;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  m=MAX(m,a*c);
  m=MAX(m,b*c);
  m=MAX(m,a*d);
  m=MAX(m,b*d);
  printf("%lld\n",m);
  return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef pair<int,int> pii;
const int inf=1e9;
const long long int infll=1e18;
const double eps=1e-9;

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

void solve(){
    int n,m,w,t;
    cin >> n >> m >> w >> t;
    map<string,int> mp;
    vector<int> v(m),p(m),l(n),x(n),y(n);
    vector<vector<string>> r(n);
    vector<vector<int>> q(n);
    rep(i,0,m){
        string s;
        cin >> s >> v[i] >> p[i];
        mp[s]=i;
    }
    rep(i,0,n){
        cin >> l[i] >> x[i] >> y[i];
        r[i].resize(l[i]);
        q[i].resize(l[i]);
        rep(j,0,l[i]) cin >> r[i][j] >> q[i][j];
    }

    vector<int> dist((1<<n)-1);
    vector<vector<int>> vis((1<<n)-1);
    rep(i,1,1<<n){
        bitset<7> bs(i);
        vector<int> perm,min_perm;
        rep(j,0,n) if(bs[j]) perm.push_back(j);
        dist[i-1]=inf;
        do{
            int d=0,prev_x=0,prev_y=0;
            for(int pos:perm){
                d+=abs(x[pos]-prev_x)+abs(y[pos]-prev_y);
                prev_x=x[pos];
                prev_y=y[pos];
            }
            d+=abs(prev_x)+abs(prev_y);
            if(dist[i-1]>d){
                dist[i-1]=d;
                min_perm=perm;
            }
            vis[i-1]=min_perm;
        }while(next_permutation(perm.begin(),perm.end()));
    }

    vector<int64_t> dp1((1<<n)-1);
    rep(k,0,(1<<n)-1){
        vector<int> dp(w+1);
        for(int pos:vis[k]){
            rep(i,0,l[pos]){
                int idx=mp[r[pos][i]];
                int weight=v[idx],diff=p[idx]-q[pos][i];
                if(diff<=0) continue;
                rep(j,0,w+1){
                    if(j-weight<0) continue;
                    dp[j]=max(dp[j],dp[j-weight]+diff);
                }
            }
        }
        dp1[k]=dp[w];
    }

    vector<int64_t> dp2(t+1);
    rep(i,0,t+1){
        rep(j,0,(1<<n)-1){
            int i_=i+dist[j];
            if(i_>t) continue;
            dp2[i_]=max(dp2[i_],dp2[i]+dp1[j]);
        }
    }
    cout << dp2[t] << endl;
}

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

Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum=0,p,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    while(m--)
	{
        cin>>p>>x;
        cout<<sum-a[p]+x<<endl;
    }
    return 0;
} 

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

using namespace std;

#define mkp(x,y) (make_pair(x,y))
typedef pair<int,int> P;

class Edge
{
public:
    int to,cap,cost,rev;
    Edge(int a,int b,int c,int d)
    {
        to=a;cap=b;cost=c;rev=d;
    }
};

class MCMF
{
public:
    vector<vector<Edge> > G;
    vector<int> dist;
    vector<int> prev,pree;
    const int INF=2e9+10;
    MCMF(int n)
    {
        G.resize(n);
        dist.resize(n);
        prev.resize(n);
        pree.resize(n);
    }
    void add(int from,int to,int cap,int cost)
    {
        G[from].emplace_back(to,cap,cost,G[to].size());
        G[to].emplace_back(from,0,-cost,G[from].size()-1);
    }
    int mcmf(int s,int t,int f)
    {
        int res=0;
        while(f>0)
        {
            priority_queue<P,vector<P>,greater<P> > q;
            fill(dist.begin(),dist.end(),INF);
            dist[s]=0;
            q.push(P(0,s));
            while(!q.empty())
            {
                P p=q.top();q.pop();
                int v=p.second;
                if(dist[v]<p.first) continue;
                for(int i=0;i<G[v].size();i++)
                {
                    Edge &e=G[v][i];
                    if(e.cap>0&&dist[e.to]>dist[v]+e.cost)
                    {
                        dist[e.to]=dist[v]+e.cost;
                        prev[e.to]=v;
                        pree[e.to]=i;
                        q.push(P(dist[e.to],e.to));
                    }
                }
            }
            if(dist[t]==INF)
            {
                return -1;
            }
            int tot=0;
            int d=f;
            for(int v=t;v!=s;v=prev[v])
            {
                Edge &e=G[prev[v]][pree[v]];
                d=min(d,e.cap);
                tot+=e.cost;
            }
            f-=d;
            for(int v=t;v!=s;v=prev[v])
            {
                Edge &e=G[prev[v]][pree[v]];
                e.cap-=d;
                G[v][e.rev].cap+=d;
            }
            res+=tot*d;
        }
        return res;
    }
};

int main()
{
    int V,E,F;
    while(cin>>V>>E>>F)
    {
        MCMF mcmf(V);
        for(int i=0;i<E;i++)
        {
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            mcmf.add(a,b,c,d);
        }
        cout<<mcmf.mcmf(0,V-1,F)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    int res=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i%2==0&&a[i]%2)res++;
    }
    printf("%d\n",res );
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003, mod = 1000000007;

int n, m;
int a[N], ton[N];
char s[N];

int main()
{
    n = gi();
    for (int i = 2; i <= n; i+=1) a[i] = gi(), ++ton[a[i]];
    for (int i = 1; i <= n; i+=1) cout << ton[i] << endl;
    return 0;
}

Measured memory_bytes: 5152
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
Arr.sort(function(a,b){return a-b;});
var ans=[];
for(var i=0;i<5;i++){
   for(var j=i+1;j<5;j++){
      ans.push((Arr[i]+Arr[j])-0);
      ans.push((Arr[j]+Arr[i])-0);
   }
}
ans.sort(function(a,b){return a-b;});
console.log(ans[2]);

Measured memory_bytes: 10160
fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val X = listOfInt()
    var ans = Int.MAX_VALUE
    for (i in 0 until N - K + 1) {
        val a = Math.abs(X[i]) + X[i + K - 1] - X[i]
        val b = Math.abs(X[i + K - 1]) + X[i + K - 1] - X[i]
        ans = Math.min(ans, Math.min(a, b))
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }

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

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for(int i=0; i<N; i++) {
        cin >> h[i];
    }
    int answer = 0;
    for(int i=0; i<N; i++) {
        if(h[i] >= K) {
            answer++;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){  
  int n;
  cin >> n;
  vector<int> h(n);
  vector<int> dp(n,inf);
  rep(i,n){
    cin >> h[i];
  }
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2; i<n; i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

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

typedef long long ll;


int n;
int main(){
    cin >> n;
    int res = 0;

    for (int i = 1; i <= n; i+=2){
        int cnt = 0;
        for (int j = 1; j <= i; j++){
            if (i % j == 0){
                cnt++;
            }
        }
        if (cnt == 8){
            res++;
        }
    }

    cout << res << endl;
}

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

int main(){
  int N;
  cin>>N;
  
  vector<int> vec1(N),vec2(N);
  
  for(int i=0;i<N;i++){
    cin>>vec1.at(i);
  }
   for(int i=0;i<N;i++){
    cin>>vec2.at(i);
  }
  
  int ans=0;
   for(int i=0;i<N;i++){
     if(vec1.at(i)-vec2.at(i)>0){
       ans+=vec1.at(i)-vec2.at(i);
     }
   }
  cout<<ans<<endl;
}
         
     
  


Measured memory_bytes: 256
function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n = Number(stdin.shift());
    const G = [];
    for (let i = 0; i < n; i++) {
        G.push(new Array(n).fill(0));
    }

    for (let i = 0; i < n; i++) {
        const d = stdin[i].trim().split(' ').map(Number);
        const r = d.slice(2);
        if(r.length) {
            for (let item of r) {
                G[d[0] - 1][item - 1] = 1;
            }
        }
        console.log(G[i].join(' '));
    }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){
	int n;cin >> n;
	double t,a;cin >> t >> a;
	int ans = -1;
	double mi = 100000000;

	REP(i,n){
		double x;cin >> x;
		if(abs(a - (t - x * 0.006)) < mi){
			mi = abs(a - (t - x * 0.006));
			ans = i;
		}
	}

	cout << ans + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;




int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=3; i <10; ++i) {
        
        vi vec(i);
        
        rep(j, i-1) {
            rep(k, j) {
                string S;
                rep(h, i) {
                    if(h > j) {
                        S += '7';
                    } else if(h > k) {
                        S += '5';
                    } else {
                        S += '3';
                    }
                }

                do {
                    if(n >= stoi(S)) {
                        ans++;
                    }
                } while(next_permutation(S.begin(), S.end()));
            }
        }
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(){
  long long i,j,n,max=-1000000,min=1000000,sum=0;
  scanf("%lld",&i);
  for(j=0;j<i;j++){
    scanf("%lld",&n);
    if(n>max){
     max=n;
    }
    if(n<min){
     min=n;
    }
    sum=sum+n;
  }
  printf("%lld %lld %lld\n",min,max,sum);
    
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<string> A(H);
    for (int i = 0; i < H; i++) {
      cin >> A[i];
    }
    vector<pair<int, int>> cur;
    vector<vector<pair<int, int>>> cands;
    function<void(int)> dfs = [&](int mask) {
      if (mask == 0) {
        cands.push_back(cur);
        return;
      }
      int a;
      for (int i = 0; i < W; i++) {
        if ((mask >> i) & 1) {
          a = i;
          break;
        }
      }
      for (int i = 0; i < W; i++) {
        if (i != a && ((mask >> i) & 1)) {
          cur.push_back(make_pair(a, i));
          dfs(mask ^ (1 << a) ^ (1 << i));
          cur.pop_back();
        }
      }
    };
    if (W % 2 == 0) {
      dfs((1 << W) - 1);
    } else {
      for (int i = 0; i < W; i++) {
        int size = cands.size();
        dfs(((1 << W) - 1) ^ (1 << i));
        for (int j = size; j < cands.size(); j++) {
          cands[j].push_back(make_pair(i, i));
        }
      }
    }
    bool res = false;
    for (auto &cand : cands) {
      map<string, int> mp;
      for (int i = 0; i < H; i++) {
        string s = A[i], t(W, '-');
        for (int j = 0; j < cand.size(); j++) {
          auto p = cand[j];
          t[j] = s[p.first];
          t[W - j - 1] = s[p.second];
        }
        ++mp[t];
      }
      bool ok = true;
      int oddPalindrome = 0;
      for (auto &e : mp) {
        string s = e.first;
        string t = string(s.rbegin(), s.rend());
        if (s != t) {
          ok &= mp[s] == mp[t];
        } else {
          if (mp[s] % 2 != 0) {
            ++oddPalindrome;
          }
        }
      }
      if (ok && oddPalindrome <= 1) {
        res = true;
        break;
      }
    }
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 1596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (5010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,wa,wb,a[N]; LL f[N][N],ans=1e18;
int main(){
	read(n),read(wa),read(wb);
	for(int i=1;i<=n;i++)read(a[i]);
	memset(f,inf,sizeof(f)),f[0][0]=0;
	for(int i=1;i<=n;i++)for(int j=0;j<=n;j++)
	if(a[i]>j)f[i][j]=min(f[i-1][j]+wa,f[i][j]),f[i][a[i]]=min(f[i][a[i]],f[i-1][j]);
	else f[i][j]=min(f[i-1][j]+wb,f[i][j]);
	for(int i=0;i<=n;i++)ans=min(ans,f[n][i]); cout<<ans;
}

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

int main(){
  string s;
  cin >> s;
  int a[26]={};
  for(int i=0;i<4;i++){
    a[s[i]-'A']++;
  }
  int x=0,y=0;
  for(int i=0;i<26;i++){
    if(a[i]==0) x++;
    if(a[i]==2) y++;
  }
  cout << (x==24&&y==2?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    vector<int> vec;
    for(int i=0; i<3; i++){
        int v = 0;
        cin >> v;
        vec.push_back(v);
    }

    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i=0; i<2; i++){
        ans += abs(vec[i] - vec[i + 1]);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    vector<int>a(100000);
    rep(i,n){
        int x;
        cin>>x;
        a[x]++;
    }

    int ans=0;

    rep2(i,1,a.size()){
        ans=max(ans,a[i-1]+a[i]+a[i+1]);

    }

    cout<<ans<<endl;

}


Measured memory_bytes: 640
//Bismillahir Rahmanir Rahim
#include<iostream>
#include<cstring>
using namespace std;

#define endl "\n"
int main()
{
    char a;
    cin>>a;
    
    if(isupper(a))
    {
        cout<<'A'<<endl;
    }
    else
    {
        cout<<'a'<<endl;
    }
}


Measured memory_bytes: 3028
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
long long a,b,r,x,S,A,B;
long long T[101];
int N;
long long H;
int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		cin>>T[ i ];
	}
	a=T[0];
	for(int i=1; i<N; i++){
		A=a;
		B=T[ i ];
		b=T[ i ];

		if(a<b){
			S=a;
			a=b;
			b=S;
		}
		r=a%b;
		while(r!=0){
			a=b;
			b=r;
			r=a%b;
		}
		H=A/b;
		a=H*B;
		}

	cout<<a<<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)

int main() {
    int a,b,h=0;
    cin >> a >> b;

    rep(i,b-a)
        h += i+1;
    cout << h-b << endl;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

def Topo_sort(x,y):
    co = cl.Counter(n for m in x.values() for n in m)
    S = cl.deque([i for i in range(y) if co[i] == 0])
    while S:
        n = S.popleft()
        yield n
        for i in x[n]:
            co[i] -= 1
            if co[i] <= 0:
                S.append(i)
    
    """
    if sum(co.values()) != 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
    """
    #閉路検出(1が存在,0が存在しない)
# g = cl.dafaultdict(set)に有向グラフを作成し(g[~] != ~ ,yはノード数) リストが帰ってくる
N,M = m()
po = [0 for i in range(N)]
num = [-1 for i in range(N)]
g = cl.defaultdict(set)
gg = cl.defaultdict(set)
for i in range(N-1+M):
    s,t = m()
    g[s-1] |= {t-1}
    gg[t-1] |= {s-1}
a = list(Topo_sort(g,N))


for i in range(N):
    ppp = a[i]
    num[ppp] = i
    if i != 0:
        dp = -1
        for nu in gg[ppp]:
            if num[nu] > dp:
                dp = num[nu]
                po[ppp] = nu+1

for i in range(N):
    print(po[i])

        



Measured memory_bytes: 120364
(n, m, p, q) = gets.chomp.split(' ').map(&:to_i)
x = gets.chomp.split(' ').map(&:to_i).sort
y = gets.chomp.split(' ').map(&:to_i).sort

f = false
if x[n - 1] < y[0] then
  (x[n - 1]+1..y[0]).each do |z|
    f = (f or ((p < z) and (z <= q)))
  end
end

puts ((f) ? 'No War' : 'War')

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main()
{
	int n;cin >> n;
	vector<ll> A(n);
	rep(i,n)cin >> A[i];
	
	vector<ll> A_sum(n);
	A_sum[0]=A[0];
	rep(i,n-1)
	{
		A_sum[i+1]=A_sum[i]+A[i+1];
	}
	sort(ALL(A_sum));
	//rep(i,n)cout<<A_sum[i]<<' ';
	ll ans=0;
	rep(i,n)if(A_sum[i]==0)ans++;
	ll l=1;
	//cout<<LLONG_MAX<<endl;
	A_sum.push_back(LLONG_MAX);
	for(int i = 0;i<n;i++)
	{
		if(A_sum[i]!=A_sum[i+1])
		{
			ans+=l*(l-1)/2;
			l=1;
		}
		else
		{
			l++;
		}
	}

	cout<<ans<<endl;

	return 0;
}

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

typedef complex<double> P;

// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)

// 外積 (cross product) : a×b = |a||b|sinΘ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

// 2直線の平行判定 : a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}

int main(){
	int n;
	double x1,x2,x3,x4,y1,y2,y3,y4;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		P a(x1,y1), b(x2,y2), c(x3,y3), d(x4,y4);
		if( is_parallel(a,b,c,d) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1224
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

const int MAX_N = 10010;
typedef unsigned long long ull;
typedef long long ll;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

struct query{
    int com, x, y;
};

struct UnionFind{
    int N;
    int par[MAX_N];
    int rank[MAX_N];

    UnionFind(int N): N(N){
        for (int i=0;i<N;i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        int rx = root(par[x]);
        par[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return;

        if(rank[rx] < rank[ry]){
            par[rx] = ry;
        }else{
            par[ry] = rx;
            if(rank[rx]==rank[ry]){
                rank[rx]++;
            }
        }
    }

    bool find(int x, int y){
        return root(x) == root(y);
    }
};

void solveUnionFindComplete(vector<query> &queries, int n){
    UnionFind uf(n);
    REP(i, queries.size()){
        query Q = queries[i];
        if(Q.com == 0){
            uf.unite(Q.x, Q.y);
        }else{
            cout << uf.find(Q.x, Q.y) << endl;
        }
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<query> queries;
    REP(i, q){
        query que;
        cin >> que.com >> que.x >> que.y;
        queries.push_back(que);
    }
    solveUnionFindComplete(queries, n);
    return 0;
}

Measured memory_bytes: 4596
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

int main()
{
	ll N,K;
	cin>>N>>K;
	vector<ll> A(N+1);
	rep(i,N){
		ll tmp;
		cin>>tmp;
		A[i+1]=A[i]+tmp-1;
	}

	ll res=0;
	map<ll,ll> mp;	
	const ll start = min(K, (ll)A.size());
	rep(i,start){
		mp[A[i]%K]++;
		//cout<<"debug "<<i<<" "<<A[i]<<endl;
	}
	for(auto& itr:mp){
		res+=itr.second*(itr.second-1)/2;
		//cout<<itr.first<<" "<<itr.second<<" "<<res<<endl;
	}
	/*
	for(auto num:A)cout<<num<<" ";
	cout<<endl;
	*/
	REP(i,start,N+1){
		const ll l = i-start;
		const ll r = i;
		const ll tgt = A[r] % K;
		/*
		for(auto itr:mp){
			cout<<itr.first<<" "<<itr.second<<endl;
		}
		*/
		mp[A[l]%K]--;
		res += mp[tgt];
		mp[A[r]%K]++;
	}

	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 14336
s = input().strip()
k = int(input())

head_count = 0
tail_count = 0
cont_count = 0
if s[0] == s[-1]:
    i = 1
    while i < len(s) and s[i] == s[0]:
        i += 1
    if i == len(s):
        print((k * len(s)) // 2)
        exit(0)
    j = len(s) - 2
    while j >= 0 and s[-1] == s[j]:
        j -= 1
    head_count = i // 2
    tail_count = (len(s) - j - 1) // 2
    cont_count = (i + len(s) - j - 1) // 2
    s = s[i:(j + 1)]
char = ''
local_cnt = 0
count = 0
for c in s:
    if c == char:
        local_cnt += 1
    else:
        count += local_cnt // 2
        local_cnt = 1
        char = c
if local_cnt >= 2:
    count += local_cnt // 2

print(head_count + count * k + cont_count * (k - 1) + tail_count)


Measured memory_bytes: 38384
h,w = gets.split.map(&:to_i)
field = Array.new(h+2).map{Array.new(w+2, "#")}
for i in 1..h
  field[i] = gets.chomp.split("")
  field[i].push("#")
  field[i].insert(0,"#")
end
dp = Array.new(h+2).map{Array.new(w+2, 0)}
for i in 1..h
  for j in 1..w
    if i == 1 && j == 1
      dp[i][j] = 1
    else
      if field[i][j] == "."
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % (10**9 + 7)
      else
        dp[i][j] = 0
      end
    end
  end
end
puts dp[h][w]


Measured memory_bytes: 101116
#include<stdio.h>

int linearSearch(int,int [10000],int);

int main(void){
	int n,q,count=0,i,j;
	int S[10000],T[10000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&T[i]);
	}
	
	for(i=0;i<q;i++){
		if(linearSearch(T[i],S,n)!=0){
			count++;
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

int linearSearch(int T,int S[10000],int n){
	int i;
	
	for(i=0;i<n;i++){
		if(T==S[i]){
			return 1;
		}
	}
	
	return 0;
}



Measured memory_bytes: 2092
#include <stdio.h>
#include<string.h>
 
int main()
{
    int n,i,T=0,H=0,f;
    char t[101],h[101];
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s%s",t,h);
        f=strcmp(t,h);
        if(f==0){T+=1;H+=1;}
        else if(f>0)T+=3;
        else H+=3;
    }
    printf("%d %d\n",T,H);
    return 0;
}


Measured memory_bytes: 2052
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        if(x < 0) {
            x = -x;
        }
        long k = sc.nextLong();
        long d = sc.nextLong();
        long div = x / d;
        if(k <= div) {
            System.out.println(x - k * d);
            return;
        }
        k -= div;
        x -= d * div;
        if(k % 2 == 0) {
            System.out.println(x);
        } else {
            System.out.println(d-x);
        }

    }


}

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

using namespace std;

int a[3][3];
int n;

int main()
{
  	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);

	for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }

    cin >> n;
    for (int _ = 0; _ < n; _++)
    {
        int b;
        cin >> b;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (a[i][j] == b)
                    a[i][j] = 0;
            }
        }
    }

    int ok = false;
    for (int i = 0; i < 3; i++)
    {
        if (a[i][0] == a[i][1] && a[i][1] == a[i][2] && a[i][2] == 0)
            ok = true;
    }

    for (int i = 0; i < 3; i++)
    {
        if (a[0][i] == a[1][i] && a[1][i] == a[2][i] && a[2][i] == 0)
            ok = true;
    }

    if (a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[2][2] == 0)
        ok = true;

    if (a[2][0] == a[1][1] && a[1][1] == a[0][2] && a[0][2] == 0)
        ok = true;

    if (ok)
        cout << "Yes";
    else
        cout << "No";


	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long int n,a,b,s=0,t,u,i;
  scanf("%ld%ld%ld%ld",&n,&a,&b,&u);
  for(i=1;i<n;i++){scanf("%ld",&t);s+=(t-u)*a<b?(t-u)*a:b;u=t;}
  printf("%ld",s);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, A, B, C;
vector<int> l;

int dfs(int n, int a, int b, int c) {
    if (n == N) return min({a,b,c}) != 0 ? abs(A-a) + abs(B-b) + abs(C-c) - 30 : 10000000;
    int no_add = dfs(n+1, a, b, c);
    int add_a = dfs(n+1, a+l[n], b, c) + 10;
    int add_b = dfs(n+1, a, b+l[n], c) + 10;
    int add_c = dfs(n+1, a, b, c+l[n]) + 10;
    return min({no_add, add_a, add_b, add_c});
}

int main() {
    cin >> N >> A >> B >> C;
    int input;
    for (int i=0; i<N; i++) { cin >> input; l.push_back(input); }
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
l_list = gets.chomp.split.map(&:to_i)

l_list.sort!

ans = 0

(0..(n-3)).each do |i|
  ((i+1)..(n-2)).each do |j|
    tmp = l_list[i] + l_list[j]
    idx = l_list.bsearch_index{|k| k >= tmp}
    if idx.nil?
      ans += n - 1 - j
    else
      ans += idx - j - 1
    end
  end
end

puts ans


Measured memory_bytes: 1912