akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 200000+5;

int n;
int h[N];
int a[N];
ll ft[N];

void update(int pos, ll val){
	pos++;
	while(pos <= n){
		ft[pos] = max(ft[pos],val);
		pos += (-pos)&pos;
	}
}

ll query(int pos){
	ll ans = 0LL;
	pos++;
	while(pos > 0){
		ans = max(ans,ft[pos]);
		pos &= pos-1;
	}
	return ans;
}

int main(){
	ri(n);
	for(int i=0; i<n; i++){
		ri(h[i]);
		h[i]--;
	}
	for(int i=0; i<n; i++){
		ri(a[i]);
	}
	ll ans = 0LL;
	for(int i=0; i<n; i++){
		ll act = query(h[i]-1) + a[i];
		ans = max(ans,act);
		update(h[i],act);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
n, k = map(int, input().split())
la = list(map(int, input().split()))

count = 0
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
        if la[i] > la[jj]:
            count += 1

count2 = 0
laa = sorted(la)
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
      
        if laa[i] < laa[jj]:
            count2 += 1

a = count * k
b = count2 * (((k-1)*k)//2)
result = int(a)+int(b)

print(result%(pow(10,9)+7))


Measured memory_bytes: 3188
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int n,m,co=0;
	while(cin>>n>>m,n){
		if(co++)cout<<endl;
		vvi cost(n,vi(n,inf));
		rep(i,n)cost[i][i]=0;
		vvp G(n);
		rep(i,m){
			int a,b,c;cin>>a>>b>>c;
			a--;b--;
			cost[a][b]=cost[b][a]=c;
			G[a].pb({b,c});
			G[b].pb({a,c});
		}
		rep(i,n)sort(all(G[i]));
		rep(k,n)rep(i,n)rep(j,n)
			cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);

		vvi go(n,vi(n,inf));
		rep(i,n)rep(j,n)if(i!=j)rep(k,G[i].size())if(cost[i][j]==G[i][k].second+cost[G[i][k].first][j]){
			go[i][j]=G[i][k].first;break;
		}

		int q;
		cin>>q;
		vi s(q),t(q),hu(n),ob(q);
		vs name(q);
		rep(i,q)cin>>s[i]>>t[i]>>ob[i]>>name[i];
		rep(i,q)s[i]--,t[i]--;
		while(1){
			int mi=inf,from=-1;
			rep(i,q)if(s[i]!=t[i]){
				int tim=max(ob[i],hu[s[i]]);
				if(mi>tim)mi=tim,from=s[i];
			}
			if(from==-1)break;

			int mi_t=inf,to=-1;
			rep(i,q)if(s[i]!=t[i]&s[i]==from){
				if(mi_t>ob[i])mi_t=ob[i],to=go[s[i]][t[i]];
				else if(mi_t==ob[i])to=min(to,go[s[i]][t[i]]);
			}

			hu[from]=mi+2*cost[from][to];
			rep(i,q)if(ob[i]<=mi&&s[i]==from&&go[s[i]][t[i]]==to){
				ob[i]=mi+cost[from][to];
				s[i]=to;
			}
		}
		vector<pair<int,string> >out(q);
		rep(i,q)out[i]={ob[i],name[i]};
		sort(all(out));
		rep(i,q)cout<<out[i].second<<" "<<out[i].first<<endl;
	}
}











Measured memory_bytes: 3228
// Maximize the Formula
#include <bits/stdc++.h>
using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;

    vector<int> x;
    x.push_back(a);
    x.push_back(b);
    x.push_back(c);

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

    int ans = (x[2]*10+x[0]+x[1]);

    cout << ans;





}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int d = Integer.parseInt(br.readLine());

		if (d == 25) {
			System.out.println("Christmas");
		} else if (d == 24) {
			System.out.println("Christmas Eve");
		} else if (d == 23) {
			System.out.println("Christmas Eve Eve");
		} else if (d == 22) {
			System.out.println("Christmas Eve Eve Eve");
		}
	}
}

Measured memory_bytes: 32444
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  vll cnt(26, 0);
  rep(i, (ll)s.size()) cnt[s[i] - 'a']++;

  bool ok = true;
  rep(i, 26) if (cnt[i] % 2 == 1) ok = false;

  string ans = ok ? "Yes" : "No";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int k, a, b;
  cin >> k >> a >> b;
  rep(i, a, b + 1) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3648
n, a, b, c, d = map(int, input().split())
s = input()

s_list = [c for c in s]

def check(start, end , s):
    kukan = "".join(s_list[start - 1 : end])
    if "##" in kukan:
        return False
    if kukan[0] == "#" or kukan[-1] == "#":
        return False
    return True

def check2(start, end, s):
    kukan = "".join(s_list[start - 1 : end])
    if "..." in kukan:
        return True
    else:
        return False

ans = check(a, c, s) and check(b, d, s)

if c > d:
    ans = ans and check2(b - 1, d + 1, s)

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 6580
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int n;
    cin >> n;
    int ans = 0,r=99999999;
    vector<int>a,b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (r >= b[i]) {
            r = b[i];
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;

}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	t := getNextInt(scanner)
	imos := make([]int, t+1)
	for i := 0; i < n; i++ {
		l := getNextInt(scanner)
		r := getNextInt(scanner)
		imos[l]++
		imos[r]--
	}
	var ans cint
	for i := 0; i < t; i++ {
		imos[i+1] += imos[i]
	}
	for i := 0; i < t+1; i++ {
		ans.maxAs(cint(imos[i]))
	}
	fmt.Fprintln(writer, ans)
}

type cint int64

func (ct *cint) minAs(x cint) *cint {
	*ct = ct.min(x)
	return ct
}
func (ct *cint) maxAs(x cint) *cint {
	*ct = ct.max(x)
	return ct
}
func (ct cint) min(x cint) cint {
	if ct > x {
		return x
	}
	return ct
}
func (ct cint) max(x cint) cint {
	if ct < x {
		return x
	}
	return ct
}



Measured memory_bytes: 4156
// Problem : E - Logs
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define 	MOD 		1000000007
#define 	vp 			vector<pair<int,int> >
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x.begin(),x.end())
#define 	dg(x)		cerr<<"--- x = "<<x<<"\n"
#define 	endl		"\n"


using namespace std;
const int N = 2e5;
ll ar[N];
ll ans = 0;
ll n,k; 

bool check(ll mid){
	ll cost = 0;
	rep(i ,1, n + 1)
		cost += ( (ar[i] - 1) / mid);
	return (cost <= k);
	
}

void solve(){
	cin >> n >> k;
	ll mx = -1;
	rep(i, 1, n+1){
		cin >> ar[i];
		mx = max(mx, ar[i]);
	}
	if(k){
	
		ll low = 1, high = mx;
		while(low < high){
			
			ll mid = low + (high - low)/2;
			if(check(mid))
				high = mid;
			else
				low = mid + 1;
		}
		cout << low;
	}
	else
		cout << mx;
}

int32_t main(){

	solve();
}


Measured memory_bytes: 5104
//beautiful Sets

#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e3+10;
int dp[N][N];
char s[N][N];
int32_t main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>s[i][j];
		}
	}
	dp[1][1]=(s[1][1]=='#');
	for(int j=2;j<=m;j++)
	{
		dp[1][j]=dp[1][j-1];
		if(s[1][j]!=s[1][j-1]&&s[1][j]=='#')
		{
			dp[1][j]+=1;
		}
	}
	for(int i=2;i<=n;i++)
	{
		dp[i][1]=dp[i-1][1];
		if(s[i][1]!=s[i-1][1]&&s[i][1]=='#')
		{
			dp[i][1]+=1;
		}
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			int x=dp[i][j-1];
			int y=dp[i-1][j];
			if(s[i][j-1]!=s[i][j]&&s[i][j]=='#')
			{
				x+=1;
			}
			if(s[i-1][j]!=s[i][j]&&s[i][j]=='#')
			{
				y+=1;
			}
			dp[i][j]=min(x,y);
		}
	}
	cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, A + B - N) << endl;
}

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

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 long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    int N; cin >> N;
    VI a(N); REP(i,N) cin >> a[i]; SORT(a);
    int r = a.back();
    int half = (r+1) / 2;

    VI n(r+1,0);
    REP(i,N) n[a[i]]++;

    REP(i,N){
        if(a[i] < half){
            cout << "Impossible" << en;
            return;
        }
    }

    FOR(i,half,r+1){
        if(r%2 == 0 && i == half){
            if(n[i] != 1){
                cout << "Impossible" << en;
                return;
            }
        }
        else if(r%2 == 1 && i == half){
            if(n[i] != 2){
                cout << "Impossible" << en;
                return;
            }
        }
        else if(n[i] < 2){
            cout << "Impossible" << en;
            return;
        }
    }

    cout << "Possible" << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fre freopen("in.txt","r",stdin)
#define IO ios::sync_with_stdio(false)
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=3.1415926;
const int MOD=1e9+7;
const int N=1e6+5;
int main()
{
    //fre;
    IO;
    int a,b,c,x;
    while(cin>>a>>b>>c>>x)
    {
        int ans=0,cnt=0;
        rep(i,0,a+1)
        {
            ans=i*500;
            if(ans>x) break;
            rep(j,0,b+1)
            {
                rep(k,0,c+1)
                if(i*500+j*100+k*50==x) cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

#define MAX 502
#define INF INT_MAX

int n;
int cap[MAX][MAX];
bool used[MAX];

int dfs(int v , int t, int f){
  if(v==t) return f;
  used[v] = true;
  rep(i,n){
    int c = cap[v][i];
    if(!used[i] && c > 0){
      int d = dfs(i , t , min(f, c));
      if(d > 0){
        cap[v][i] -= d;
        cap[i][v] += d;
        return d;
      }
    }
  }
  return 0;
}

int mf(int s, int t){
  int flow = 0;
  for(;;){
    memset(used , 0 , sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main(void){
  int e,q;

  while(scanf("%d%d%d",&n,&e,&q) != EOF){
    memset(cap,-1,sizeof(cap));

    rep(i,e){
      int from,to;
      scanf("%d%d",&from,&to);
      from--;
      to--;
      cap[from][to] = cap[to][from] = 1;
    }

    int res = mf(0,n-1);

    while(q--){
      int flg,a,b;
      scanf("%d%d%d",&flg,&a,&b);
      a--;
      b--;

      if(flg == 1){
        cap[a][b] = cap[b][a] = 1;
        res += mf(0,n-1);
      }
      else{
        if(cap[a][b] != 1){
          if(cap[a][b] != 0) swap(a,b);
          memset(used,0,sizeof(used));
          int tmp = dfs(a,b,1);
          if(tmp != 1){
            memset(used,0,sizeof(used));
            dfs(a,0,1);
            memset(used,0,sizeof(used));
            dfs(n-1,b,1);
            res--;
          }
        }
        cap[a][b] = cap[b][a] = -1;
      }
      /*
      rep(i,n){
        rep(j,n){
          printf("%3d",cap[i][j]);
        }
        cout<<endl;
      }
        cout<<endl;
      */
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 1880
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int res = 0;
        for (int i = a; i <= b; i++) {
            if (c%i == 0) {
                res++;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 26240
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] linesp = line.split(" ");
        int r = Integer.parseInt(linesp[0]);
        int c = Integer.parseInt(linesp[1]);
        int[][] mat = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++) {
            String line1 = sc.nextLine();
            String[] line1sp = line1.split(" ");
            for(int j = 0; j < c; j++) {
                mat[i][j] = Integer.parseInt(line1sp[j]);
            }
        }
        int[] tatesum = new int[c];
        for(int i = 0; i < r; i++) {
            int yokosum = 0;
            for(int j = 0; j < c; j++) {
                yokosum += mat[i][j];
                tatesum[j] += mat[i][j]; 
            }
            mat[i][c] = yokosum;
        }
        int sum = 0;
        for(int j = 0; j <= c; j++) {
            if(j < c) {
                mat[r][j] = tatesum[j];
                sum += tatesum[j];
            }
            if(j == c) {
                mat[r][c] = sum;
            }
        }
        
        for(int i = 0; i <= r; i++) {
            for(int j = 0; j <= c; j++) {
                System.out.print(mat[i][j]);
                if(j < c) {
                    System.out.print(" ");
                }
            }
            System.out.println("");
         }
        
  }
 }


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int NextPow2(int x)
{
	x--;
	for(int i=1;i<32;i*=2) x|=x>>i;
	return x+1;
}

const int I=0;
int F(int a,int b){return a+b;}

struct SegmentTree{
	int size;
	vi data;
	SegmentTree(int n):size(NextPow2(n)),data(size*2,I){}
	SegmentTree(const vi& a):size(NextPow2(a.size())),data(size*2,I){
		copy(all(a),begin(data)+size);
	}
	void Update(int a,int b,int x,int i,int l,int r){
		if(b<=l || r<=a) return;
		if(a<=l && r<=b){
			data[i]=F(data[i],x);
			return;
		}
		Update(a,b,x,i*2+0,l,(l+r)/2);
		Update(a,b,x,i*2+1,(l+r)/2,r);
	}
	void Update(int a,int b,int x){
		Update(a,b,x,1,0,size);
	}
	int Query(int i){
		int res=I;
		for(i+=size;i;i/=2) res=F(res,data[i]);
		return res;
	}
};

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		vi ls(n),rs(n);
		rep(i,n) cin>>ls[i]>>rs[i];

		map<int,vi> f;
		rep(i,n) f[rs[i]-ls[i]+1].push_back(i);

		vi sum(m+1);
		rep(i,m+1) sum[i]=f[i].size();
	 	per(i,m) sum[i]+=sum[i+1];

		SegmentTree st(m+1);
		repi(d,1,m+1){
			int res=sum[d];
			for(int i=d;i<=m;i+=d)
				res+=st.Query(i);
			cout<<res<<endl;
			for(int i:f[d])
				st.Update(ls[i],rs[i]+1,1);
		}
	}
}


Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
long long n,p;
char s[200010];
map<long,long>mp;
int main(){
	cin>>n>>p;
	cin>>s;
	long long ans=0;
	if(10%p==0){
	for(int i=0;i<n;i++){
		if((s[i]-'0')%p==0) ans+=i+1;
   }
  }
  else{
  	//从低位往上搞
  	long long res=0,t=1;
		for(int i=n-1;i>=0;i--){
			res=res+(s[i]-'0')*t;
			res%=p;
			t=t*10%p;
			if(res==0) ans++;
			ans+=mp[res];
			mp[res]++;
		}
	}
	cout<<ans<<'\n';
}
	

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

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

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

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

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

int main(){
    int a,b;cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
}

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

int N;

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


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

int main() {
  int N, M, S;
  cin >> N >> M;
  S = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    S += A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  if (A.at(M - 1) * 4 * M >= S) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

a, b, c = inls()

if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:print('NO')


Measured memory_bytes: 3696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int[] as;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        as = new int[3];
        for (int i = 0; i < 3; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        Arrays.sort(as);
        System.out.println(as[0] + as[1]);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23252
// ------------------------------------
// Date:2018/ 2/28
// Problem:ABC 054 TemplateMatching b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

bool check(int x, int y);

int N, M;
string a[50];
string b[50];

int main()
{
  cin >> N >> M;
  REP(i, N) cin >> a[i];
  REP(i, M) cin >> b[i];
  bool ok;
  int h, w;
  h = w = 0;
  REP(yi, N - M + 1) {
    REP(xi, N - M + 1) {
      ok = true;
      REP(hi, M) {
        if (a[hi + yi].substr(xi, M) != b[hi]) {
          ok = false;
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No"<< endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b,k;
    cin>>a>>b>>k;

    int count = 0 ,res= 0;
    for(int i=min(a,b); i>=1; i--)
    {
        if(a%i==0 && b%i==0)
        {
            count++;
        }
        if(count==k)
        {
            res = i;
            break;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int k, n;
	cin >> k >> n;
	const int N = 6005;
	vector <vector<ll>> dp(N, vector<ll>(N));
	for (int i = 0; i < N; i++)
		dp[i][0] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j < N; j++) {
			if(i < j)	continue;
			dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
		}
	}
	
	vector <ll> pw2(N);
	pw2[0] = 1;
	for (int i = 1; i < N; i++) {
		pw2[i] = (pw2[i - 1] * 2) % MOD;
	}
	for (int i = 2; i <= 2 * k; i++) {
		ll ans = 0;
		int pairs;
		if(i <= k + 1) 
			pairs = i / 2;
		else
			pairs = i / 2 - (i - (k + 1));
		int iEven = (i % 2 == 0);
		int others = k - pairs * 2 + iEven;
		pairs -= iEven;
		for (int j = 0; j <= pairs; j++) {
			if(j == 0 && others == 0)	continue;
			ans += ((dp[pairs][j] * pw2[j]) % MOD) * dp[n + others - 1][others + j - 1];
			ans %= MOD;
		}
		if(iEven) {
			for (int j = 0; j <= pairs; j++) {
				if(j == 0 && others == 0)	continue;
				ans += ((dp[pairs][j] * pw2[j]) % MOD) * dp[n - 1 + others - 1][others + j - 1];
				ans %= MOD;
			}	
		}
		cout << ans << "\n";
	}
}


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

int main() {
	// your code goes here
	int x=1;
	int y=1;
	
	while(x!=0)
	{
	    
		cin>>x;
		if(x!=0)
		{
		cout<<"Case "<<y<<": "<<x<<endl;
		y+=1;
		}
	}
	return 0;
}


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

long long int gcd(long long int a, long long int b) {
  if(a%b == 0) return b;
  else return gcd(b, a%b);
} 

int main() {
  long long int a, b;
  cin >> a >> b;
  if(a > b) {
    cout << a / gcd(a, b) * b << endl;
  } else {
    cout << b / gcd(b, a) * a << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    ll X, v = 100; //intにすると大幅に遅くなる（2ms -> 2005ms）

    cin >> X;

    rep(ret, INF){ //whileにしても実行時間に大きな差はない
        if(X<=v){
            cout << ret << endl;
            break;
        }
        v *= INT;
    }

    /*
    int ret=0;
    while(true){
        ret++;
        v *= INF;
        if(X<=v) break;
    }
    cout << ret << endl;
    */

    return 0;
}


/* 以下悪いコード

#define INT 1.01

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

    ll X;
    cin >> X;

    int ret = 0, v = 100;
    while(true){
        ret ++;
        v *= INT;
        if(X<=v) break;
    }

    cout << ret << endl;

    return 0;
}
*/

Measured memory_bytes: 3608
from collections import deque
import numpy as np
 
S=deque(input())
Q=int(input())
count = 0
L=np.array([input().split() for _ in range(Q)])
 
for i in range(Q):
  l=L[i]
  if len(l)==1:
    count+=1
    continue
  elif len(l)==3:
    F=int(l[1])
    C=l[2]
    if (count%2==1) ^ (F==1):
      S.appendleft(C)
    else:
      S.append(C)
 
if count%2==1:
  S.reverse()
print(''.join(S))

Measured memory_bytes: 64716
require 'scanf'

sum, num, ndata = 0, 0, 0
while s = STDIN.gets
    u, n = s.scanf("%d,%d")
    sum += u * n
    num += n 
    ndata += 1
end

av = (num.to_f/ndata.to_f).round(0)
print "#{sum}\n#{av}\n"

Measured memory_bytes: 8956
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
int i = 0;
    for(;;){
      int h = sc.nextInt();
      int w = sc.nextInt();

      if(h == 0 && w == 0) break;

      for( i = 0;i < h ;i++){
        for(int p = 0; p < w; p++){
        System.out.print("#");

        //System.out.println("i = "+i+";");
        if((i != 0) && (i != h-1)){
            for(int q = 0;q<w-2;q++){
              //System.out.println("i :"+i+" ");
              System.out.print(".");

            }//q
            System.out.print("#");
            break;
          }else{
            //System.out.println("else");
        }



        }//p
        System.out.println("");
      }//i
      System.out.println("");

    }//for;;

  }//main


}//class


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

int main() {
int n;
cin>>n;
vector<P>list(n);
rep(i,n)
{int x,l;
scanf("%d %d",&x,&l);
P p;
  //firstに、アームを一番右側に伸ばしたときの数字
  p.first=x+l;
  //secondに、アームを一番左側に伸ばした時の数字(かぶってはいけないので)
  p.second=x-l;
  list.at(i)=p;
}
sort(list.begin(),list.end());

int nowx=-1e9;
int ans=0;
rep(i,n)
{P p=list.at(i);
  if(nowx<=p.second)
  {ans++; nowx=p.first;}
}

cout << ans << endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 

#define PI acos(-1.0)

int main(int argc, char** argv) {
    fast_io
   
	
	double r;
	cin >> r;
	
	cout << fixed << setprecision(5) << PI * r * r << " " << 2.0 * PI * r << endl;
	
	

    return 0;
}























Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0 ; i < n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    for (auto si : s) cout << si;
    cout << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    Long A = sc.nextLong();
    Long B = sc.nextLong();
    Long round;
    Long amari;
    Long ans;
    
    round = N / (A + B);
    amari = N % (A + B);
    if (amari > A) amari = A;
    ans = A * round + amari;
    
    System.out.println(ans);
  
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    ll jou=1;
    if(n%2)jou=2;
    ll dp[n+1][2][jou+1];
    rep(i,0,n+1){
        rep(j,0,2)rep(k,0,jou+1)dp[i][j][k]=-inf;
    }
    dp[0][0][0]=0;
    rep(i,0,n){
        rep(j,0,2){
            rep(k,0,jou+1){
                if(j==0){
                    Max(dp[i+1][1][k],dp[i][j][k]+a[i]);
                    if(k<jou){
                        Max(dp[i+1][0][k+1],dp[i][j][k]);
                    }
                }
                else{
                    Max(dp[i+1][0][k],dp[i][j][k]);
                }
            }
        }
    }
    
    ll ans=-inf;
    rep(i,0,2){
        rep(j,jou-1,jou+1)Max(ans,dp[n][i][j]);
    }
    cout<<ans<<endl;
}



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

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> v(s.size());
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      v.at(i) = cnt;
      cnt++;
    } else {
      v.at(i) = cnt;
    }
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << v.at(r - 1) - v.at(l - 1) << endl;
  }
}


Measured memory_bytes: 1408
#encoding: utf-8

def main():
    N,M=map(int,input().split())
    if(abs(N-M)>=2):
        print(0)
        return

    ret=1
    mod=10**9+7
    for i in range(1,N+1):
        ret*=i
        ret%=mod
    for i in range(1,M+1):
        ret*=i
        ret %= mod
    if(N==M):
        r=2
    else:
        r=1
    print((ret*r)%mod)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;



int main() {


	int n, m;
	cin >> n >> m;
	vector<int> a(ARRAY_MAX, 0);

	for (int i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		a[l]++;
		a[r + 1]--;
	}

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

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

	return 0;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		List<int[]> list = new ArrayList<>();
		for(int i=0;i<n;i++) {
			int[] tmp = new int[2];
			tmp[0] = in.nextInt();
			tmp[1] = in.nextInt();
			list.add(tmp);
		}
		list.sort((a,b)->(-a[1]+b[1]));
		boolean[] used = new boolean[100001];
		long[] ans = new long[100001];
		long tmp_ans = 0;
		int num_variation = 0;
		Queue<int[]> p_que = new PriorityQueue<>((a,b)->(a[1]-b[1]));
		for(int i=0;i<k;i++) {
			tmp_ans += list.get(i)[1];
			if(used[list.get(i)[0]]==false) {
				used[list.get(i)[0]] = true;
				num_variation++;
			}else {
				p_que.add(list.get(i));
			}
		}
		ans[num_variation] = tmp_ans;
		int i = k;
		while(i<n) {
			if(used[list.get(i)[0]]==false) {
				if(p_que.isEmpty()) break;
				else {
					tmp_ans = tmp_ans - p_que.poll()[1] + list.get(i)[1];
					used[list.get(i)[0]] = true;
					num_variation++;
					ans[num_variation] = tmp_ans;
				}
			}else {
				//continue
			}
			i++;
		}
		long max = 0;
		for(i=0;i<=num_variation;i++) {
			if(ans[i]==0) continue;
			else {
				max = Math.max(max, ans[i] + (long)i*(long)i);
			}
		}
		System.out.println(max);
		in.close();
		
	}

}


Measured memory_bytes: 93956
N=int(input())
inp=[]
for _ in range(N):
    inp.append(int(input()))
inp.sort()

if N%2:
    
    m1=inp[:(N//2+1)]
    M1=inp[(N//2+1):]
    
    m2=inp[:N//2]
    M2=inp[N//2:]
    
    a1=sum(M1)*2-sum(m1)*2+m1[-1]+m1[-2]
    a2=sum(M2)*2-sum(m2)*2-M2[0]-M2[1]
    
    print(max(a1,a2))
    
else:
    
    m=inp[:N//2]
    M=inp[N//2:]
    
    a=sum(M)*2-sum(m)*2+m[-1]-M[0]
    
    print(a)

Measured memory_bytes: 8532