akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,sum[3010],l[3010],r[3010],f[3010][3010],c[3010][3010];
char a[3010];

int main()
{
    int t;
    scanf("%d%d%s",&n,&t,a+1);
    repu(i,1,n)
        sum[i]=sum[i-1]+(a[i]=='1');
    while (t--)
    {
        scanf("%d%d",&l[m+1],&r[m+1]);
        m+=r[m+1]>r[m];
    }
    sum[l[m+1]=r[m+1]=n+1]=sum[n],f[0][0]=1;
    repu(i,0,n)
    {
        c[i][0]=1;
        repu(j,1,i)
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
    }
    repu(i,0,m)
        repu(j,0,r[i]-l[i]+1)
            if (f[i][j])
            {
                int cnt=sum[r[i+1]]-sum[max(l[i+1]-1,r[i])];
                if (l[i+1]>r[i])
                    f[i+1][cnt]=(f[i+1][cnt]+LL(f[i][j])*c[r[i]-l[i]+1][j])%p;
                else
                {
                    int x=max(j-(l[i+1]-l[i]),0);
                    int y=min(j,r[i]-l[i+1]+1);
                    repu(k,x,y)
                        f[i+1][cnt+k]=(f[i+1][cnt+k]+LL(f[i][j])*c[l[i+1]-l[i]][j-k])%p;
                }
            }
    printf("%d\n",f[m+1][0]);
    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> mochi(N);
  for(int i = 0; i < N; i++) {
    cin >> mochi[i];
  }
  
  sort(mochi.begin(), mochi.end());
  reverse(mochi.begin(), mochi.end());
  
  int count = 0;
  int prev = 999;
  for(int i = 0; i < N; i++) {
    if(mochi.at(i) < prev) {
      prev = mochi.at(i);
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;
struct process {
	string name;
	int time;
};
int main(void) {
	int n, q;
	cin >> n >> q;
	queue<process> p;
	for (int i = 0;i < n;i++) {
		string s;
		int in;
		cin >> s >> in;
		p.push({ s,in });
	}
	int totaltime = 0;
	while (!p.empty()) {
		int num = p.front().time;
		string str = p.front().name;
		p.pop();
		int c = min(q, num);
		num -= c;
		totaltime += c;
		if (num > 0) p.push({ str,num});
		else cout << str << " " << totaltime << endl;
	}
	return 0;
}


Measured memory_bytes: 6224
#include <stdio.h>
 
void find3(int n);
  
int main(void) {
    int n;
      
    scanf("%d",&n);
    find3(n);
     
    printf("\n");
    return 0;
}
 
void find3(int n){
    int i;
     
    for(i=1;i<=n;i++){
        if(i % 3 == 0)
            printf(" %d",i);
        else if (i % 10 == 3)
            printf(" %d",i);
        /*else if (i / 10 == 3)
            printf(" %d",i);
        else if (i / 100 == 3)
            printf(" %d",i);*/
        else if (i / 1000 == 3)
            printf(" %d",i);
        else if (i % 1000 / 100 == 3)
            printf(" %d",i);
        else if (i % 100 / 10 == 3)
            printf(" %d",i);
        else{}
         
    }
}

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

int main(void) {
      int l, i=0, a[10];
  		while(cin>>l){
          a[i] = l;
          //cout << a[i];
          i++;
        } 
  if(a[0] == 0){
    cout << 1;
  }
    if(a[1] == 0){
    cout << 2;
  }
    if(a[2] == 0){
    cout << 3;
  }
    if(a[3] == 0){
    cout << 4;
  }
    if(a[4] == 0){
    cout << 5;
  }
    if(a[5] == 0){
    cout << 6;
  }
}


Measured memory_bytes: 3632
n = int(input())
a = [int(x) for x in input().split()]
cnt1 = 0
cnt2 = 0
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 == 0:
        if total >= 0:
            cnt1 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt1 += 1 - total
            total += 1 - total
total = 0
for i in range(len(a)):
    total += a[i]
    if i % 2 != 0:
        if total >= 0:
            cnt2 += 1 + total
            total -= 1 + total
    else:
        if total <= 0:
            cnt2 += 1 - total
            total += 1 - total
print(min(cnt1, cnt2))


Measured memory_bytes: 14468
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

const int N = 100005;
VI ys[N];
VI xs[N];
bool visit[N];

int main() {
	int n;
	scanf("%d", &n); 
	vector<PII> xy(n);
	REP(i, n) {
		int x, y;
		scanf("%d%d", &x, &y);
		xs[y].PB(i);
		ys[x].PB(i);
		xy[i] = MP(x, y);
	}
	LL ans = 0;
	REP(i, n) {
		if (visit[i])continue;
		queue<int> q;
		unordered_set<int> xx;
		unordered_set<int> yy;
		q.push(i);
		int cnt = 0;
		while (!q.empty()) {
			auto tmp = q.front();
			q.pop();
			if (visit[tmp])continue;
			visit[tmp] = true;
			xx.insert(xy[tmp].first);
			yy.insert(xy[tmp].second);
			cnt++;
			for (auto idx : ys[xy[tmp].first]) {
				q.push(idx);
			}
			for (auto idx : xs[xy[tmp].second]) {
				q.push(idx);
			}
		}
		ans += xx.size() * yy.size() - cnt;
	}
	cout << ans << endl;
	return 0;
}

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

int MOD = 1e9 + 7;
int prv[200009], A[200009], D[200009];

int main() {
    vector<int> S = {0};
    int N; scanf("%d",&N);
    for(int i=1, p=-1; i<=N; i++) {
        int foo; scanf("%d",&foo);
        if(p != foo) S.push_back(foo);
        p = foo;
    }
    D[0] = 1;
    N = (int)S.size() - 1;
    for(int i=1; i<=N; i++) {
        int pr = prv[S[i]];
        D[i] = D[i-1] + (pr ? D[pr] : 0);
        D[i] %= MOD;
        prv[S[i]] = i;
    }
    printf("%d", D[N]);
    return 0;
}

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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if (b>n+1){
        ll p=n*a;
        p/=b;
        ll q=n/b;
        q*=a;
        cout<<p-q<<endl;
    }
    else{
        ll p=a/b;
        if (a%b!=0) p+=1; 
        cout<<a-p<<endl;
    }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
long long mygcd(long long a, long long b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  else return mygcd(b,a%b);
}
int main() {
  long long k;
  cin>>k;
  long long ans=0;
  for(long long a=1;a<=k;a++){
    for(long long b=1;b<=k;b++){
      for(long long c=1;c<=k;c++){
        long long x=mygcd(a,b);
        ans+=mygcd(x,c);
      }
    }
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll dp[405][405];

ll pre[403];
int main(){
	fastio();
	ll n;
	cin>>n;
	ll a[n+1];
	
	for(int i=1;i<=n;i++) cin>>a[i];

	for(int i=1;i<=n;i++){
		pre[i]=a[i]+pre[i-1];
	}

	
	ll ans=0;
	
	for(int l=1;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			
			int j = i+l-1;
			if(i==j) continue;
			dp[i][j] = INF;
			for(int k=i;k<j;k++){
				dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+pre[j]-pre[i-1]);
			}
		}	
	}

	// for(int i=1;i<=n;i++){
	// 	for(int j=1;j<=n;j++){
	// 		if(i<j){
	// 			cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
	// 		}
	// 	}
	// }
	
	cout<<dp[1][n];

}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;


int main() {
    fast;
    ll N, X, T;
    cin >> N >> X >> T;


    cout << (N/X + (N%X?1:0)) * T << "\n";
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    map<ll, ll> m;

    rep(i, n) { m[-a[i]]++; }

    ll ans = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        ll num = -(iter->first);

        ll x = 1;
        while (x <= num) {
            x *= 2;
        }
        ll pair = x - num;

        if (pair == num) {
            ans += iter->second / 2;
            iter->second %= 2;
            continue;
        }

        while (iter->second != 0) {
            if (m[-pair] > 0) {
                m[-pair]--;
                ans++;
                iter->second--;
            } else {
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 30176
S = input()
L = len(S)

ans = 0
counter = 0
for i in range(L):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
        counter += 1
    else:
        if ans < counter:
            ans = counter
        counter = 0

if ans < counter:
    ans = counter
    
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N + 1);
  A.at(0) = 2;  // 0番目の定義
  A.at(1) = 1;  // 1番目の定義

  for (int i = 2; i <= N; i++) {
    A.at(i) = A.at(i - 1) + A.at(i - 2);
  }

  cout << A.at(N) << endl;
}


Measured memory_bytes: 256
data = input().split()
a = int(data[0])
b = int(data[1])
while(a != 0 or b != 0):
	if a > b:
		temp = a
		a = b
		b = temp
	print(str(a) + " " + str(b))
	data = input().split()
	a = int(data[0])
	b = int(data[1])
	

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

int N, M;
vector<pair<int, int>> CB;

int
main()
{
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    CB.emplace_back(make_pair(a * -1, 1));
  }
  for (int i = 0; i < M; i++) {
    int b, c; cin >> b >> c;
    CB.emplace_back(make_pair(c * -1, b));
  }


  sort(CB.begin(), CB.end());

  int index = 0;
  unsigned long long num = 0;
  for (int i = 0; i < CB.size() && index < N; i++) {
    if (N - index < CB.at(i).second) {
      CB.at(i).second = N - index;
    }
    num += (unsigned long long)CB.at(i).first * CB.at(i).second * -1;
    index += CB.at(i).second;
  }

  cout << num << endl;
}
/*
3 2
5 1 4
2 3
1 5
 */


Measured memory_bytes: 2420
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
	fast;
	string s,t;
	cin>>s>>t;
	string ss = t.substr(0,(int)s.size());
	if(ss == s)
		cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, a[15], x[15][15], y[15][15], ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        for(int j=0;j<a[i];j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    
    for(int k=0;k<(1<<n);k++){
        bool ok = true;
        for(int i=0;i<n;i++){
            for(int j=0;j<a[i];j++){
                if(((k>>i)&1) == 1 && ((k>>x[i][j])&1) != y[i][j]){
                    ok = false;
                }
            }
        }
        if(ok){
            int v = 0;
            for(int i=0;i<n;i++){
                if(((k>>i)&1)==1)v++;
            }
            ans = max(ans, v);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m;
  cin >> n >> m;
  if(m > (n - 1) * (n - 2) / 2) {
    cout << -1;
  } else {
    vector<pair<int, int>> vec;
    for (int i = 2; i <= n; ++i) {
      vec.push_back({1, i});
    }
    int L = 2, R = 3;
    int limit = (n - 2) * (n - 1) / 2;
    while(limit != m) {
      vec.push_back({L, R});
      --limit;
      if(R == n) {
        ++L;
        R = L + 1;
      } else {
        ++R;
      }
    }
    cout << vec.size() << '\n';
    for(auto it: vec)
      cout << it.first << ' ' << it.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] d = new int[N];
    for (int i = 0; i < N; i++) d[i] = sc.nextInt();
    Arrays.sort(d);
    System.out.println(d[N/2-1] == d[N/2] ? 0 : d[N/2]-d[N/2-1]);
  }
}

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

using namespace std;

//#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<int,ii> iii2;
typedef pair<ii,ii> iiii;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;

vector<long long> addv,maxi;

int ul,ur;
long long uv;

void update(int o,int l,int r){
	if(ul<=l&&ur>=r){
		addv[o]+=uv;
		maxi[o]+=uv;
	}else{
		int m = (l+r)/2;
		if(ul<=m) update(o*2,l,m);
		if(ur>m) update(o*2+1,m+1,r);
		maxi[o] = max(maxi[o*2],maxi[o*2+1]);
		maxi[o]+=addv[o];
	}
}


int ql,qr;
long long qv;
void query(int o,int l,int r,long long add){
	if(ql<=l&&qr>=r){
		qv = max(qv,maxi[o]+add);
	}else{
		int m = (l+r)/2;
		if(ql<=m) query(o*2,l,m,add+addv[o]);
		if(qr>m) query(o*2+1,m+1,r,add+addv[o]);
	}
}

int main(){

	int n,m;
	cin>>n>>m;
	vector<int> l,r;
	vector<long long> a(m,0);
	l.assign(m,0);
	r  = l;
	vector<vector<int> > adj(n+1,vector<int>());
	for(int i=0;i<m;i++){
		scanf("%d%d%lld",&l[i],&r[i],&a[i]);
		a[i] = -a[i];
		l[i]--;
		adj[r[i]].push_back(i);
	}

	maxi.assign(4*n+10,0);
	addv = maxi;

	for(int i=1;i<=n;i++){

		qv = -large;
		ql = 0;
		qr = i-1;
		query(1,0,n,0);
		ul = ur = i;
		uv = qv;
		update(1,0,n);
		for(int j=0;j<(int)adj[i].size();j++){
			int id = adj[i][j];
			ur = l[id];
			ul = 0;
			uv = a[id];
			update(1,0,n);
		}
	}

	long long ans = 0;
	for(int i=0;i<m;i++) ans+=a[i];
	ans-=maxi[1];
	cout<<-ans<<endl;









	return 0;
}


Measured memory_bytes: 26880
#include<stdio.h>

int n, m, q;
int id = 1;
int A[100000][100];
int B[100000], C[100000];

void sns(int s) {
   int i, j;
   B[s] = id;
   
   for (i = 0; i < C[s]; i++) {
      if (B[A[s][i]] == 0) {
         sns(A[s][i]);
      }
   }
}

int main() {
   int a, b, i, j, m, n;
   
   scanf("%d %d", &n, &m);
   for (i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      A[a][C[a]++] = b;
      A[b][C[b]++] = a;
   }
   for (i = 0; i < n; i++) {
      if (B[i] == 0) {
         sns(i);
         id++;
      }
   }

   scanf("%d", &q);
   for (i = 0; i < q; i++) {
      scanf("%d %d", &a, &b);
      if (B[a] == B[b]) {
         printf("yes\n");
      } else {
         printf("no\n");
      }
   }
   return 0;
}



Measured memory_bytes: 44636
N = int(input())
A = list(map(int, input().split()))
count = 0
RET = 0

while True:
    for i in range(N):
        if A[i] % 2 == 1:
            RET = 1
        else:
            A[i] /= 2
    if RET == 1:
        break
    else:
        count += 1

print(count)


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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define PI      acos(-1.0)
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll x;
	if(b-1<=n) x=(ll) floor((b-1)*a*1.0/b)-a*floor((b-1)*1.0/b);
	else x=(ll) floor(n*a*1.0/b)-a*floor(n*1.0/b);
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a;
  cin >> a;
  if(a == 'a' || a == 'i'|| a == 'u'|| a == 'o'|| a == 'e')
  cout << "vowel" << endl;
  else
  cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}

// 逆元
ll mod_inv(ll a, ll m)
{
	return pow_mod(a,m-2,m);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> a(n);
    ll u=0,v=0;
    REP(i,n){
        cin >> a[i];
        (u+=a[i])%=mod;
        (v+=a[i]*a[i]%mod)%=mod;
    }
    cout << (u*u%mod-v+mod)%mod*mod_inv(2,mod)%mod << endl;
}

Measured memory_bytes: 4780
function NotOne(arr){
   var cnt=[0,0,0,0,0,0,0,0,0,0];
   arr.forEach(function(v){cnt[(v-0)]++;});
   var bad=[];
   cnt.forEach(function(v,i){if(v>=2)bad.push(i);});
   var result=[];
   arr.forEach(function(v,i){if(bad.indexOf(v)!=-1)result.push(i);});
   return result;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.trim().split("\n");
var STR="";
var n=Arr.shift()-0;
for(var I=0;I<n;I++){
   var yx=[];
   var YX=[];
   for(var i=0;i<9;i++){
      var v=Arr.shift().split(" ").map(Number);
      yx.push(v);
      YX.push([0,0,0,0,0,0,0,0,0]);
   }
   for(var i=0;i<9;i++){
      var re=NotOne(yx[i]);
      re.forEach(function(v){YX[i][v]++;});
   }
   for(var i=0;i<9;i++){
      var yy=[];
      for(var j=0;j<9;j++)yy.push(yx[j][i]);
      var re=NotOne(yy);
      re.forEach(function(v){YX[v][i]++;});
   }
   for(var y=0;y<3;y++){
      for(var x=0;x<3;x++){
         var i=y*3;
         var j=x*3;
         var z=[
         [0+i,0+j],[0+i,1+j],[0+i,2+j],
         [1+i,0+j],[1+i,1+j],[1+i,2+j],
         [2+i,0+j],[2+i,1+j],[2+i,2+j]
         ];
         var zz=[];
         z.forEach(function(v){zz.push(yx[v[0]][v[1]]);});
         var re=NotOne(zz);
         re.forEach(function(v){YX[z[v][0]][z[v][1]]++;});
      }
   }
   yx.forEach(function(V,i){
      V.forEach(function(v,j){
         yx[i][j]=(YX[i][j]>=1)?"*"+v:" "+v;
      });
   });
   STR+=yx.join("\n").replace(/\,/g,"")+"\n\n";
}
console.log(STR.trim());

Measured memory_bytes: 10140
//130a.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
/*namespace*/
using namespace std;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int X,A;
    cin>>X>>A;
    if(X<A){
        cout<<0<<endl;
    }else{
        cout<<10<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string S;
  string T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U) --A;
  else --B;
  cout << A << ' ' << B << '\n';  
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int a[n];
    int MAX = 0;
    int MIN = inf;
    int check;
    int ans = inf;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        MAX = max(MAX, a[i]); MIN = min(MIN, a[i]);
    }
    sort(a, a+n);
    for(int i = MIN; i <= MAX; i++){
        check = 0;
        for(int j = 0; j < n; j++)
            check += (i-a[j])*(i-a[j]);
        ans = min(ans, check);    
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    ans=S.count('R') * S.count('G') * S.count('B')
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
main()


Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        boolean[] hasOkashi = new boolean[N];

        for (int i = 0; i < K; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                hasOkashi[sc.nextInt() - 1] = true;
            }
        }
        sc.close();
        
        int count = 0;
        for(int i=0;i<N; i++) {
            if(!hasOkashi[i]) {
                count++;
            }
        }
        System.out.println(count);
    }

}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 10e-10;
const int MAX_V = 10000;

vector<int> G[MAX_V], rG[MAX_V], vs;
int component[MAX_V];
bool used[MAX_V];
int V,E;

void add_edge(int s, int t){
    G[s].push_back(t);
    rG[t].push_back(s);
}

void dfs(int node){
    used[node] = true;
    for(int next: G[node]){
        if(!used[next]) dfs(next);
    }
    vs.push_back(node);
}

void rdfs(int node, int k){
    used[node] = true;
    component[node] = k;
    for(int next: rG[node]){
        if(!used[next]) rdfs(next, k);
    }
}

void scc(){
    memset(used, false, sizeof(used));
    rep(V){
        if(!used[i]) dfs(i);
    }
    memset(used, false, sizeof(used));
    int k = 0;
    reverse(all(vs));
    for(int i: vs){
        if(!used[i]) rdfs(i, k++);
    }
}


int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int s,t;
    cin >> V >> E;
    rep(E){
        cin >> s >> t;
        add_edge(s, t);
    }

    scc();

    int Q, u, v;
    cin >> Q;
    rep(Q){
        cin >> u >> v;
        cout << (component[u] == component[v]?1:0) << endl;
    }
}


Measured memory_bytes: 4884
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N), y(M);
	REP(i, N) cin >> x[i];
	REP(i, M) cin >> y[i];
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	string res;
	if (max(x[N - 1], X) < min(y[0], Y)) res = "No War";
	else res = "War";
	cout << res << "\n";

	return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int H,W;
  cin>>H>>W;
  vector<vector<int>>A(H,vector<int>(W)),B(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A[i][j];
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>B[i][j];
    }
  }
  vector<vector<vector<int>>>dp(H,vector<vector<int>>(W,vector<int>((80+80)*80+1)));
  dp[0][0][abs(A[0][0]-B[0][0])]=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<=(80+80)*80;k++){
        if(i+1<H){
          dp[i+1][j][k]|=dp[i][j][k+abs(A[i+1][j]-B[i+1][j])];
          dp[i+1][j][k]|=dp[i][j][abs(k-abs(A[i+1][j]-B[i+1][j]))];
        }
        if(j+1<W){
          dp[i][j+1][k]|=dp[i][j][k+abs(A[i][j+1]-B[i][j+1])];
          dp[i][j+1][k]|=dp[i][j][abs(k-abs(A[i][j+1]-B[i][j+1]))];
        }
      }
    }
  }
  for(int k=0;k<=(80+80)*80;k++){
    if(dp[H-1][W-1][k]){
      cout<<k;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 324608
#include <iostream>

int main() {
	int x(0), y(0);
	long long int Y, N, sum;
	std::cin >> N >> Y;
	sum = Y - 1000 * N;
	bool flg = false;
	for (x = 0; x <= N; ++x) {
		for (y = 0; y <= N - x; ++y) {
			if (9000 * x + 4000 * y == sum) {
				flg = true;
			}
			if (flg) break;
		}
		if (flg) break;
	}
	if (flg)
		std::cout << x << " " << y << " " << N - (x + y) << "\n";
	else
		std::cout << "-1 -1 -1" << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

signed main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b,d)-max(a,c));

}


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

int main()
{
  int N;
  cin >> N;
  vector<long long> name_count(5, 0);
  rep(i, N)
  {
    string S;
    cin >> S;
    if (S[0] == 'M')
      name_count[0]++;
    else if (S[0] == 'A')
      name_count[1]++;
    else if (S[0] == 'R')
      name_count[2]++;
    else if (S[0] == 'C')
      name_count[3]++;
    else if (S[0] == 'H')
      name_count[4]++;
  }
  long long ans = 0;
  for (int i = 0; i < 5; i++)
  {
    for (int j = i + 1; j < 5; j++)
    {
      for (int k = j + 1; k < 5; k++)
      {
        ans += name_count[i] * name_count[j] * name_count[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
object Main extends App {
  
  val sc = new java.util.Scanner(System.in) 
  val x1, y1, x2, y2 = sc.nextInt()
  val xd = x1 - x2
  val yd = y1 - y2
  print(x2 + yd)
  print(" ")
  print(y2 - xd)
  print(" ")
  print(x1 + yd)
  print(" ")
  print(y1 - xd)
}

Measured memory_bytes: 55100
#include <bits/stdc++.h>
using namespace	std;
static int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int h,w,r;
string s[20];
void dfs(int y,int x){
  r++;
  s[y][x]='#';
  for(int i=0;i<4;i++)
      if(0<=y+dy[i]&&y+dy[i]<h&&0<=x+dx[i]&&x+dx[i]<w)
	if(s[y+dy[i]][x+dx[i]]=='.') dfs(y+dy[i],x+dx[i]);
}
int main(){

  int y,x;
  for(;cin>>w>>h,w;){
  r=0;
  for(int i=0;i<h;i++) cin>>s[i];
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(s[i][j]=='@') y=i,x=j;
  dfs(y,x);
  cout<<r<<endl;
  }
  return 0;
}

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

int main() {
  int n, x;
  cin >> x;
  if (x >= 10000)
    cout << "1";
  else {
    n = x / 100;
    if (x <= 105 * n)
      cout << "1";
    else
      cout << "0";
  }
  return 0;
}

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

using namespace std;

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

	int N;
	cin >> N;
	vector<int> A(N + 1);
	for(int i = 1; i <= N; ++i)
	{
		cin >> A[i];
	}
	vector<pair<int64_t, int64_t> > dp(N + 1);
	dp[0].first = 0;
	dp[0].second = 0;
	dp[1].first = 0;
	dp[1].second = A[1];
	for(int i = 2; i <= N; ++i)
	{
		if(i & 1)
		{
			// odd
			dp[i].first = max
				({
					dp[i - 1].first,
					dp[i - 1].second,
					dp[i - 2].first + A[i]
				});
			dp[i].second = dp[i - 2].second + A[i];
		}
		else
		{
			dp[i].first = dp[i].second = max
				({
					dp[i - 1].second,
					dp[i - 2].first + A[i],
					dp[i - 2].second + A[i]
				});
		}
	}

	cout << dp[N].first << "\n";

	return 0;
}


Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<a*b/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ii> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

int main(){
    int n;cin>>n;
    int s[n],t[n],p[n];
    for(int i=0;i<n;i++) cin>>s[i]>>t[i]>>p[i];
    int dp[n+1][394];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=393;j++){
            dp[i][j]=-1;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=393;j++){
            dp[i+1][j]=dp[i][j];
            for(int k=s[i];k<=p[i];k++){
                if(j>=k&&dp[i+1][j-k]!=-1) dp[i+1][j]=max(dp[i+1][j],dp[i+1][j-k]+p[i]);
            }
        }
    }
    int m;cin>>m;
    int ans[m];
    for(int i=0;i<m;i++){
        int w;cin>>w;
        ans[i]=dp[n][w];
        if(ans[i]==-1){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3692
s = input()
q = int(input())
b = True
left = []
right = []
for _ in range(q):
  query = input()
  if query == "1":
    b = not(b)
  else:
    t, f, c = query.split()
    if int(f) + b == 2:
      left.append(c)
    else:
      right.append(c)
s = "".join(left)[::-1] + s + "".join(right)
print(s if b else s[::-1])

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (S[0] == 'W' || S[2*N-1] == 'W') {
        cout << 0 << endl;
        return 0;
    }

    string d;

    d.pb('l');
    for (int i=1; i<2*N; i++) {
        if (S[i] == 'B') {
            if (i % 2 == 0) {
                d.pb('l');
            }
            else {
                d.pb('r');
            }
        }
        else {
            if (i % 2 == 0) {
                d.pb('r');
            }
            else {
                d.pb('l');
            }
        }
    }
    /* 
    if (d[2*N-1] == 'l') {
        cout << 0 << endl;
        return 0;
    }
    */
    ll ans = 1;
    ll lef = 0, rig = 0;
    
    REP(i,2*N) {
        if (d[i] == 'l') {
            lef++;
        }
        else {
            ans *= lef;
            ans %= MOD;
            lef--;
        }
    }
    ans %= MOD;

    if (rig != lef) {
        cout << 0 << endl;
        return 0;
    }

    REP(i,N) {
        ans *= (i+1);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;   
}

Measured memory_bytes: 776
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n, m;
vector<vector<int>> g;
int macnt = 0;

void dfs(int cnt, int now, vector<int> &visited){
    //cout << now << " " << cnt << endl;
    if(cnt == n){
        macnt++;
        visited[now] = 0;
        return;
    }

    for(int i = 0; i < g[now].size(); i++){
        int next = g[now][i];
        if(visited[next]) continue;
        visited[next] = 1;
        dfs(cnt + 1, next, visited);
    }

    visited[now] = 0;
}

int main(void){
    cin >> n >> m;
    g.resize(n);

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> visited(n, 0);
    visited[0] = 1;
    dfs(1, 0, visited);
    cout << macnt << endl;
}   

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

int main() {
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(),arr.end());
	arr[n-1] /= 2;

	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += arr[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}
	sort.Ints(as)

	ans := as[n/2] - as[n/2-1]
	fmt.Println(ans)
}


Measured memory_bytes: 6320
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	unordered_set<int> lasin;
	int cn;
	for(int a=0;a<b;a++){
		cin>>cn;
		lasin.insert(cn);
	}
	for(int i=0;;i++){
		if(lasin.find(a-i)==lasin.end()){
			cout<<a-i<<endl;
			return 0;
		}
		else if(lasin.find(a+i)==lasin.end()){
			cout<<a+i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    int N,A,B;
    SCD3(N,A,B);
    if ((B-A-1) % 2 == 0) cout << "Borys" << endl;
    else cout << "Alice" << endl;
}


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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = min(a, b) + min(c, d);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int N,A,max = 0,min = 0,result = 0;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> A;

		if (max <= A)
		{
			max = A;
		}
		
		if (min == 0)
		{
			min = A;
		}
		else if (min > A)
		{
			min = A;
		}
	}
	result = max - min;

	cout << result << endl;
}

Measured memory_bytes: 256
def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  A.sort()
 
  if N % 2 == 1 and A.count(0) != 1:
    print(0)
    return 0
  elif N % 2 == 0 and A.count(0) > 0:
    print(0)
    return 0
  
  if N % 2 == 1:
    A.pop(0)
  
  cnt = 0
  while len(A) > 0:
    if A[0] != A[1] or (len(A) > 2 and A[0] == A[1] and A[1] == A[2]):
      print(0)
      return 0
    elif A[0] == A[1] == 2 * cnt + (N % 2) + 1:
      cnt += 1
      A.pop(0)
      A.pop(0)
    else:
      print(0)
      return 0
 
  ans = 1
  for p in range(cnt):
    ans = (ans * 2) % 1000000007
  print(ans)

main()

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

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

struct UnionFind {
   vector<int> node;
   UnionFind(int n) : node(n,-1) {}
   bool unionSet(int x, int y) {
      x = root(x); 
      y = root(y);
      if (x != y) {
         if (node[y] < node[x]) swap(x, y);
         node[x] += node[y]; 
         node[y] = x;
      }
      return x != y;
   }
   bool findSet(int x, int y) {
      return root(x) == root(y);
   }
   int root(int x) {
      return node[x] < 0 ? x : node[x] = root(node[x]);
   }
   int size(int x) {
      return - node[root(x)];
   }
};

int main() {
   UnionFind inst(100010);
   int n,q; cin >> n >> q;
   REP(i,q){
      int com,x,y; cin >> com >> x >> y;
      if(com == 0) inst.unionSet(x,y);
      else cout << inst.findSet(x,y) << endl;
   }
   return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int frow[n],srow[n],sum[n];
    for(int i=0;i<n;i++){
        scanf("%d",&frow[i]);
        sum[i]=0;}
    for(int i=0;i<n;i++)
        scanf("%d",&srow[i]);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n-i;j++)
        {
            sum[i]+=frow[j];
        }
        for(int j=n-i-1;j<n;j++)
        {
            sum[i]+=srow[j];
        }

    }

    sort(sum,sum+n);

    printf("%d\n",sum[n-1]);

    return 0;

}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n-1;i>0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define P pair<int,int>
#define Pll pair<ll,ll>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    int n,m; cin >> n >> m;
    bool ok[n];
    rep(i,n)ok[i]=0;
    int ans[n];
    rep(i,n) ans[i]=0;
    int res=0;
    rep(i,m){
        int p; cin >> p;
        p--;
        string s; cin >> s;
        if(s=="WA"){
            ans[p]++;
        }else{
            if(ok[p]==0){
                ok[p]=1;
                res+=ans[p];
            }
        }
    }
    int a=0;
    rep(i,n){
        if(ok[i]) a++;
    }
    cout << a << endl;
    cout << res << endl;
}


Measured memory_bytes: 768
n,k=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
score_max=max(C)
#スタート地点＝L
for L in range(n):
  score=0
  d=[0]*n
  r=0
  d[L]=1
  #k回移動する
  for _ in range(k):
    r+=1#移動回数をカウント
    L=P[L]-1#移動先の位置
    score+=C[L]
    score_max=max(score,score_max)
    #もしも移動した場所に未到達なら...
    if d[L]==0:
      d[L]=1
    #Cの0未満ならスコアは減り続けるのでbreak
    elif score<0:
      break
    else:
      #ループ可能回数を調べてscoreにかける
      #最後の1周とあまりは一個ずつ見る
      roop=(k//r)-1
      h=(k%r)+r
      score*=roop
      score_max=max(score,score_max)

      #あまりの移動の処理
      for _ in range(h):
        L=P[L]-1
        score+=C[L]
        score_max=max(score,score_max)
      break
print(score_max)

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

namespace ABC142B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var p = ReadInt();
            int count = 0;
            for (int i = 0; i < n - 2; i++)
            {
                if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) count++;
                else if (p[i + 2] < p[i + 1] && p[i + 1] < p[i]) count++;
            }

            Console.WriteLine(count);

            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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

using namespace std;


int main(void)
{
	int a,b,maxn;
	cin >> a >> b;
	maxn = a*b;
	maxn = max(maxn,a+b);
	maxn = max(maxn,a-b);
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    int l,r,d; cin>>l>>r>>d;
    int o = 0;
    for(; l<=r; l++) o += l%d==0;
    cout<<o;
}

Measured memory_bytes: 3652
import Control.Applicative
main = do
    ns <- map read . words <$> getLine
    putStrLn (if circle_is_in ns then "Yes" else "No")
circle_is_in :: [Int] -> Bool
circle_is_in [w, h, x, y, r] | (x - r) >= 0 && (x + r) <= w && (y - r) >= 0 && (y + r) <= h = True
                             | otherwise = False

Measured memory_bytes: 3616