akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll INF=1e15;
 
int main(){
    ll n,m,x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n,vector<ll>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    ll ans=INF;
    for(ll i=0;i<(1<<n);i++){
        vector<ll> sum(m);
        ll s=0;
        rep(j,n){
            if((i>>j)%2==1){
                s+=c[j];
                rep(k,m){
                    sum[k]+=a[j][k];
                }
            }
        }
        bool ok=true;
        rep(j,m){
            if(sum[j]<x){
                ok=false;
                break;
            }
        }
        if(ok){
            ans=min(ans,s);
        }
    }
    if(ans==INF) cout << -1 << endl;
    else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	int N;
	map<int,int> A_list;

	int Q;
	vector<int> B_arr,C_arr;

	cin>>N;

	ll sum = 0;
	
	REP(i,N){
		int a;
		cin>>a;
		A_list[a]++;
		sum += static_cast<ll>(a);
	}

	cin>>Q;
	B_arr.resize(Q);
	C_arr.resize(Q);
	
	REP(i,Q){
		cin>>B_arr[i]>>C_arr[i];
	}
	
	REP(i,Q){

		int numb = A_list[B_arr[i]];
		A_list[B_arr[i]] = 0;

		A_list[C_arr[i]] += numb;
		sum += static_cast<ll>(C_arr[i] * numb - B_arr[i] * numb);
		cout<<sum<<endl;
	}
	return 0;
}



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

int main() {
	int n, y;
	cin >> n >> y;
	int a = -1, b = -1, c = -1, tmp;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j + i <= n; j++) {
			tmp = n - i - j;
			if (i * 10000 + j * 5000 + tmp * 1000 == y && tmp >= 0) {
				a = i;
				b = j;
				c = n - a - b;
				break;
			}
		}
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long INF = 1ll << 62;
long long w[100] = {};
long long v[100] = {};
long long dp[100][100001] = {};
bool flags[100][100001] = {};

long long rec(int i, int j) {
    // cout << "(i, j) = " << i << ", " << j << endl;
    if(flags[i][j] || i == 0 || dp[i][j] < INF) {
        // cout << "i == 0 || dp[i][j] < INFなので" << dp[i][j] << endl;
        flags[i][j] = true;
        return dp[i][j];
    }
    else if(j - v[i] < 0) {
        // cout << "j - v[i] < 0なのでrec(i, j-1)へ遷移" << endl;
        flags[i][j] = true;
        return dp[i][j] = rec(i-1, j);
    }
    else {
        // cout << "min (rec(i-1, j), rec(i-1, j-v[i])+w[i](=" << w[i] << "))へ遷移します" << endl;
        flags[i][j] = true;
        long long tmp1 = rec(i-1, j);
        long long tmp2 = rec(i-1, j-v[i])+w[i];
        dp[i][j] = min(tmp1, tmp2);
        // cout << "遷移結果: tmp1 = " << tmp1 << ", tmp2 = " << tmp2 << ", よって" << dp[i][j] << endl;
        return dp[i][j];
    }
}

int main() {
    int N, W; cin >> N >> W;
    int V = 0;
    for(int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
        V += v[i];
    }

    for(int i = 0; i < N; ++i) {
        for(int j = 1; j <= V; ++j) {
            dp[i][j] = INF;
        }
    }

    for(int i = 1; i <= v[0]; ++i) {
        dp[0][i] = w[0];
    }

    for(int i = 1; i <= V; ++i) {
        rec(N-1, i);
    }

    long long max_v = 0;
    for(int i = 0; i <= V; ++i) {
        if(dp[N-1][i] <= W) max_v = i;
    }
    // for(int i = 0; i < N; ++i) {
    //     for(int j = 0; j <= V; ++j) {
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }

    cout << max_v << endl;
}


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

typedef long long ll;
const ll MAXN = 1e5 + 5;
const long long MOD = 1e9 + 9;
const long double eps = 1e-6;

#define mp make_pair
#define pb push_back
#define all(temp) temp.begin(), temp.end()




int main()
{
    vector<ll> a,b;
    int x = 9;
    while(x <= MAXN){
        a.pb(x);
        x *= 9;
    }
    x = 6;
    while(x <= MAXN){
        a.pb(x);
        x *= 6;
    }
    a.pb(1);
    sort(all(a));

    /*for(int i = 0; i < a.size(); ++i){
        cout << a[i] << " ";
    }*/
    cout << "\n";
    ll N; cin >> N;
    vector<int> dp(MAXN-2);
    dp[1] = 1;
    for(int i = 2; i < dp.size(); ++i){
        dp[i] = MOD;
        for(int j = 0; j < a.size(); ++j){
            if(i >= a[j]){
                dp[i] = min(dp[i], dp[i - a[j]] + 1);
            }
        }
    }
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	ans := make([]int, 0)
	for {
		var a, b, v int
		var op string
		fmt.Scan(&a, &op, &b)
		if op == "?" {
			break
		}
		switch op {
		case "+":
			v = a + b
		case "-":
			v = a - b
		case "/":
			v = a / b
		case "*":
			v = a * b
		}
		ans = append(ans, v)
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}



Measured memory_bytes: 1128
package main

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

func main() {
	Count := readBigLineInt()[0]
	Results, Keys := map[int]int{}, make([]int, Count)

	for i, v := range readBigLineInt() {
		Results[v] = i
		Keys[i] = v
	}
	sort.Ints(Keys)
	Len := len(Keys)
	for i, v := range Keys {
		fmt.Print(Results[v] + 1)
		if Len != i {
			fmt.Print(" ")
		}
	}

}

/////////////////////////////////////////
func readBigLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readBigLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readBigLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

Measured memory_bytes: 12928
#include <stdio.h>
#define MAX 8
#define ON 1
#define OFF -1
#define TRUE 2
#define FALSE 3
//recursive
int x[MAX];//yoko,
int y[MAX];//tate
int r[2*MAX-1],l[2*MAX-1],c[MAX][MAX];
void set(){
  int i,j;
  for(i=0;i<MAX;i++){
    y[i]=x[i]=ON;
    for(j=0;j<MAX;j++)c[i][j]=FALSE;
  }
  for(i=0;i<MAX*2-1;i++)
    l[i]=r[i]=ON;
}
void output(){
  int i,j;
  for(i=0;i<MAX;i++)
    for(j=0;j<MAX;j++) if(c[i][j]==TRUE && x[i]!=j) return;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++)
      if(x[i] == j) printf("Q");
      else printf(".");
    printf("\n");
  }
}
void calc(int i){
  int j;
  if(i==MAX) output();
  for(j=0;j<MAX;j++){
    if(y[j]==OFF || l[i+j]==OFF || r[i-j+MAX-1]==OFF) continue;
    x[i]=j;
    y[j]=l[i+j]=r[i-j+MAX-1]=OFF;
    calc(i+1);
    x[i]=y[j]=l[i+j]=r[i-j+MAX-1]=ON;
  }
}
int main(){
  int i,num,s,t;
  set();
  scanf("%d", &num);
  for(i=0;i<num;i++){
    scanf("%d%d",&s,&t);
    c[s][t]=TRUE;
  }
  calc(0);
  return 0;
}



Measured memory_bytes: 2104
def d(n):
  return len(str(n))

N=int(input())
if N==1:
  print(1)
else:
  i=0
  #print(int(N**0.5))
  while N%(int(N**0.5)-i)!=0:
    i=i+1
  print(max(d(int(N**0.5)-i),d(N//(int(N**0.5)-i))))

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int change = 0;
    for(int i=1;;i++){
      if(1000*i >= n){
        change = 1000*i - n ;
        break;
      }
    }
    System.out.println(change);
  }
}

Measured memory_bytes: 35652
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#define ll long long
#define N 200005
using namespace std;
int n,x,y;ll sum;
struct pi{
	ll a,b;
	pi(){};
	pi(ll _a,ll _b){
		a=_a;b=_b;
	}
}tmp[N];
vector<pi>h[N];
struct pl{int l,r,lv,rv;}s[N];
void add(int a,int b,int c){
	if(s[a].l==0) s[a].l=b,s[a].lv=c;
	else s[a].r=b,s[a].rv=c;
}
bool cmp(const pi &A,const pi &B){return A.a<B.a||A.a==B.a&&A.b<B.b;} 
void dfs(int a,int fa,ll v,int w){
	if(s[a].l==0){h[a].push_back(pi(w,w));return;}
	else dfs(s[a].l,a,v,s[a].lv),dfs(s[a].r,a,v,s[a].rv);
	if(h[s[a].l].size()>h[s[a].r].size()) swap(s[a].l,s[a].r),swap(s[a].lv,s[a].rv);
	if(h[s[a].l].size()==0) return;
	int l=0,top=0;
	for(int i=0;i<h[s[a].l].size();i++){
		while(l<h[s[a].r].size()&&h[s[a].r][l].a+h[s[a].l][i].b<=v) l++;
		if(l!=0) top++,tmp[top]=pi(h[s[a].l][i].a+w,h[s[a].r][l-1].b+w);
	}
	int tip=top;
	for(int i=1;i<=tip;i++)
		if(tmp[i].a!=tmp[i].b) top++,tmp[top]=pi(tmp[i].b,tmp[i].a);
	sort(tmp+1,tmp+1+top,cmp);
	if(top!=0) h[a].push_back(tmp[1]);
	for(int i=2;i<=top;i++)
		if(tmp[i].b<h[a][h[a].size()-1].b) h[a].push_back(tmp[i]);
}
int main()
{
	//freopen("cc.in","r",stdin);
	//freopen("cc.out","w",stdout);
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&x,&y),add(x,i,y),sum+=y;
	ll l=0,r=sum;
	while(l+1<r){
		ll mid=(l+r)/2;
		for(int i=1;i<=n;i++) h[i].clear();
		dfs(1,0,mid,0);
		if(h[1].size()!=0) r=mid;else l=mid;
	}
	for(int i=1;i<=n;i++) h[i].clear();
	dfs(1,0,l,0);if(h[1].size()!=0) r--;else l++;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 32936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

const int MAX_N = 100010;
vector<pair<int, int> > G[MAX_N];
vector<int> dijkstra(int start){
	vector<int> dist(MAX_N, INF);
	dist[start] = 0;//dist[i] :=???start->i?????§??????????????¢
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >  que;
	que.push(make_pair(0, start));
	while(!que.empty()){
		int cost; int u;//????????§???????????£????????? ?????¨?????????
		cost = que.top().first, u = que.top().second;
		que.pop();
		if(dist[u] < cost) continue;
		for (auto tmp : G[u]){
			int v = tmp.first; int time = tmp.second;//??£??\???????????? ?????????????????§????????????
			if(dist[v] > dist[u] + time){//u->v
				dist[v] = dist[u] + time;
				que.push(make_pair(dist[v], v));
			}
		}
	}
	return dist;
}

int N, M, s, t;
int x[300010], y[300010];
set<int> dists[100010], distg[100010];

int main(void){
	scanf("%d %d %d %d", &N, &M, &s, &t);
	s--, t--;
	rep(i, M) scanf("%d %d", &x[i], &y[i]);
	rep(i, M) x[i]--, y[i]--;
	rep(i, M) G[x[i]].pb(mp(y[i], 1)), G[y[i]].pb(mp(x[i], 1));
	auto start = dijkstra(s);
	auto goal  = dijkstra(t);

	rep(i, N) if(start[i] != INF) dists[start[i]].insert(i);
	rep(i, N) if(goal[i]  != INF) distg[goal[i]].insert(i);
	// set<pair<int, int> > ans;
	ll ans = 0;
	int len = start[t];
	// printf("len %d\n", len);
	rep(i, len - 1){
		int d1 = i;
		int d2 = (len - 2) - i;
		// printf("d1 %d d2 %d\n", d1, d2);
		for(auto u : dists[d1]){ // s -> u ??? ?????¢ d1
			// u ??¨ v?????°????????°??????
			if(distg[d2].count(u) == 0) ans += distg[d2].size();
			else ans += distg[d2].size() - 1;
			/*
			for(auto v : distg[d2]){
				// printf("%d %d\n", u, v);
				if(u != v) ans.insert(mp(min(u, v), max(u, v)));
			}
			*/
		}
	}
	// printf("%d\n", (int)ans.size());
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 31128
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long y) {
	long long r = 1LL<<60;
	if (y >= x) r = min(r, y - x);
	if (-y >= x) r = min(r, -y - x + 1);
	if (y >= -x) r = min(r, y - -x + 1);
	if (-y >= -x) r = min(r, -y - -x + 2);
	return r;
}
int main() {
	int x, y;
	cin >> x >> y;
	cout << f(x, y) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long maps[3005][3005]={0};
long long dp[3005][3005][5]={0};
int main(){
  int h,w;
  int k;
  
  
  cin>>h>>w;
  cin>>k;
  for(int i=0;i<k;i++){
    int r,c,v;
    cin>>r>>c>>v;
    maps[r][c]=v;
  }
  

  dp[1][1][1]=maps[1][1];
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      for(int l=3;l>=0;l--){
	dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][l]);
	dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][l]+maps[i+1][j]);
	dp[i][j+1][l]=max(dp[i][j+1][l],dp[i][j][l]);
	if(l<3){
	  dp[i][j+1][l+1]=max(dp[i][j+1][l+1],dp[i][j][l]+maps[i][j+1]);
	}
      }
    }
  }
  
  long long maxim=0;
  for(int i=0;i<=3;i++){
    maxim=max(maxim,dp[h][w][i]);
  }
  cout<<maxim<<endl;
  return(0);
}

Measured memory_bytes: 426092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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 n;
vector<string> ans;

void dfs(string s, char mxc){
    if(s.size() == n){
        ans.push_back(s);
        return;
    }
    char adc = 'a'-1;
    while(true){
        adc++;
        string t = s + adc;
        dfs(t, max(adc,mxc));
        if(adc == mxc+1) break;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    dfs("a", 'a');

    for(auto a : ans){
        cout<<a<<endl;
    }
    
}

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

int main()
{
	while(1) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		if (x > y) {
			cout << y <<" "<< x << endl;
		}
		else {
			cout << x <<" "<< y<<endl;
		}
	}
    return 0;
}

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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define fora(i, x) for (auto i : x)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back
#define _1 first
#define _2 second

typedef long long ll;

const int N3 = 1e3 + 5;
const int N4 = 1e4 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int N7 = 1e7 + 5;
const int N8 = 1e8 + 5;
const int N9 = 1e9 + 5;
const int mod = N9 + 2;

ll a[4];

int main()
{
    cin >> a[1] >> a[2] >> a[3];
    sort(a + 1, a + 4);
    ll x = a[3] / 2;
    ll y = a[3] - x;
//    cout << x << " " << y;
    cout << abs((x * a[1] * a[2]) - (y * a[1] * a[2]));
}


Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0

for i in range(N+1):
    for j in range(N+1):
        if i+j>N:
            continue
        
        l = []
        
        for k in range(i):
            l.append(V[k])
        
        for k in range(j):
            l.append(V[N-1-k])
        
        if len(l)>K:
            continue
        
        l.sort()
        cnt = K-len(l)
        now = 0
        
        while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
        ans = max(ans, sum(l[now:]))

print(ans)

Measured memory_bytes: 41840
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N,M,Q;
struct node
{
	int a,b,c,d;
}qq[maxn];
int A[maxn];
int res = 0;
void dfs(int id,int last = 1){
	if(id > N){
		int sum = 0;
		for(int i = 1;i<=Q;i++){
			if(A[qq[i].b] - A[qq[i].a] == qq[i].c)
				sum += qq[i].d;
		}
		res = max(res,sum);
	}else{
		for(int i = last;i<=M;i++){
			A[id] = i;
			dfs(id+1,i);
		}
	}
}
int main(){
	// debug;
	ios;

	cin>>N>>M>>Q;
	for(int i = 1;i<=Q;i++){
		cin>>qq[i].a >> qq[i].b >> qq[i].c>>qq[i].d;
	}
	dfs(1);
	cout<<res<<'\n';

	return 0;
}


Measured memory_bytes: 3572
# N = int(input())
# A = list(map(int, input().split()))
# 
# S = sorted(A)
# MAXS = max(A)
# 
# for i in range(N):
#     if A[i] == MAXS:
#         print(S[-2])
#     else:
#         print(S[-1])
# 


n = int(input())
a = list()
for i in range(n):
    a.append(int(input()))
c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)

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

using namespace std;

int main()
{
    const auto stations = [] {
        vector<char> stations(52);
        iota(begin(stations), begin(stations) + 26, 'a');
        iota(begin(stations) + 26, end(stations), 'A');
        return stations;
    }();
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            return 0;
        }

        vector<int> keys;
        for (int i = 0; i < n; ++i) {
            int k;
            cin >> k;
            keys.push_back(k);
        }

        string s;
        cin >> s;

        // repeat key vector
        while (keys.size() < s.size()) {
            vector<int> temp(keys);
            copy(begin(keys), end(keys), back_inserter(temp));
            swap(keys, temp);
        }

        auto decrypt = [&stations](char c, int key) {
            auto stationIndex = 'a' <= c && c <= 'z' ? c - 'a' : c - 'A' + 26;
            // 52's complement
            auto minus = stations.size() - key;
            auto decryptedIndex = (stationIndex + minus) % stations.size();
            return stations[decryptedIndex];
        };

        for (size_t i = 0; i < s.size(); ++i) {
            cout << decrypt(s[i], keys[i]);
        }
        cout << endl;
    }
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first



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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    char c;
  	for(int i=0;i<3;++i){
    	cin >>c;
        if(c=='1')++ans;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

// #define int long long
#define endl '\n'
int32_t main()
{

   int n;
   cin>>n;
   string s,temp;
   cin>>s;
   temp=s;
   int cnt=0;
   sort(s.begin(),s.end());
   for(int i=0;i<n;i++){
   	if(temp[i]!=s[i])
   		cnt++;
   }
   cout<<cnt/2;
    return 0;
}


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

bool isRecursive(string s)
{
    int n = s.size();
    string rev = s;
    reverse(rev.begin(), rev.end());
    for (auto i = 0; i < n / 2; i++)
    {
        if (rev[i] != s[i])
        {
            return false;
        }
    }
    return true;
}

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

    int n = s.size();

    bool isSuccess = true;
    int half = n/2;

    string pre = s.substr(0, half);
    string post = s.substr(half+1, half);
    
    //cout << pre << " " << post << endl; 

    if (isRecursive(s) && isRecursive(pre) && isRecursive(post))
    {
        isSuccess = true;
    }
    else
    {
        isSuccess = false;
    }
    
    if (isSuccess)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int n,m;
  cin>>n>>m;
  vi a(n+10);
  rep(i,m){
    int l,r;
    cin>>l>>r;
    a[l]++;
    a[r+1]--;
  }
  rep(i,n+9){
    a[i+1]+=a[i];
  }
  int ans=0;
  rep(i,n+1){
    ans+=a[i]==m;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main(){
	int n=0;
	int four=0;
	int two=0;
	int other=0;
	cin >> n;
	for(int i=0;i<n;i++){
		int temp=0;
		cin >> temp;
		if(temp%4==0){
			four++;
		}else if(temp%2==0){
			two++;
		}else{
			other++;
		}
	}
	if(two==1){
		other++;
		two--;
	}
	if((two!=0&&four>=other) || (two==0&&four>=other-1)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsgned ll
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
struct Node{int x,v;}p[MAXN];int n,l[MAXN],r[MAXN],f[MAXN],s[MAXN];pint a[MAXN];
int rt,tot,Min[MAXN*30],ls[MAXN*30],rs[MAXN*30];
inline int newNode(){return ++tot,ls[tot]=rs[tot]=0,Min[tot]=1e9,tot;}
void Ins(int&x,int l,int r,int p,int v){
	if(!x)x=newNode();Min[x]=min(Min[x],v);if(l==r)return;int mid=l+r>>1;
	p<=mid?Ins(ls[x],l,mid,p,v):Ins(rs[x],mid+1,r,p,v);
}
int Que(int x,int l,int r,int ql,int qr){
	if(!x)return 1e9;if(ql<=l&&r<=qr)return Min[x];int mid=l+r>>1,tmp=1e9;
	if(ql<=mid)tmp=min(tmp,Que(ls[x],l,mid,ql,qr));if(qr>mid)tmp=min(tmp,Que(rs[x],mid+1,r,ql,qr));return tmp;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	Rep(i,1,n)p[i].x=read(),p[i].v=read();
	sort(p+1,p+n+1,[](Node a,Node b){return a.v<b.v;});
	Rep(i,1,n)Ins(rt,1,1e9,p[i].x,i),l[i]=Que(rt,1,1e9,p[i].x,1e9);
	tot=rt=0;
	Red(i,n,1)Ins(rt,1,1e9,p[i].x,n-i+1),r[i]=n-Que(rt,1,1e9,1,p[i].x)+1;
	Rep(i,1,n)a[i]=mk(l[i],r[i]);sort(a+1,a+n+1,[](pint x,pint y){return x.se^y.se?x.se<y.se:x.fi<y.fi;});
	Rep(i,1,n)l[i]=a[i].fi,r[i]=a[i].se;f[0]=1,s[0]=1;
	Rep(i,1,n){
		int t=lower_bound(r,r+n+1,l[i]-1)-r;
		f[i]=(s[i-1]-(t?s[t-1]:0)+Mod)%Mod,s[i]=(s[i-1]+f[i])%Mod;
	}int t=lower_bound(r+1,r+n+1,n)-r;
	cout<<(s[n]-s[t-1]+Mod)%Mod;
	return 0;
}





Measured memory_bytes: 41264
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,x,y,r;cin>>w>>h>>x>>y>>r;
    h-=r;w-=r;
    if(r<=x&&x<=w&&r<=y&&y<=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

signed main()
{
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return 0;
}

Measured memory_bytes: 256
number_list=[]
for i in range(2):
    a=input().split()
    number_list.append(a)
for n in range(int(number_list[0][0])):
    if n!=int(number_list[0][0])-1:
        print('{0} '.format(number_list[1][int(number_list[0][0])-1-n]), end='')
    else:
        print('{0}'.format(number_list[1][int(number_list[0][0])-1-n]))

Measured memory_bytes: 7668
def main():
    H, W = map(int, input().split())

    S = [
        input().split()
        for _ in range(H)
    ]
    for h in range(H):
        for w in range(W):
            if S[h][w] == "snuke":
                l = [chr(o) for o in range(ord("A"), ord("Z")+1)]
                ans = l[w] + str(h+1)
                print(ans)
                return


if __name__ == '__main__':
    main()


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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

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


int main()
{
    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe";
    else cout << "safe";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char c=getchar();
	switch(c)
	{
		case 'A':puts("T");break;
		case 'C':puts("G");break;
		case 'G':puts("C");break;
		case 'T':puts("A");break;
	}
	return 0;
}

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

using namespace std;

int main() {
long long  N;
int mod = 1000000007;
    cin >> N ;
unsigned long long product_a=1,product_b=1,product_c=1;
  for (int i = 0; i < N; ++i) {
  product_a *=10;
  product_a %= mod;  
  product_b *=9;
  product_b %= mod;
  product_c *=8;
  product_c %= mod;
  }
unsigned long long ans;
  ans=mod+mod+product_a+product_c-product_b-product_b;
  ans %= mod;
  cout << ans << endl;  
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    int n = s.length();
    for(int i = 0; i + 1 < n; ++i){
        if(s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    for(int i = 0; i + 2 < n; ++i){
        if(s[i] == s[i + 2]){
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll sum=0;
    vector<ll> cnt;
    rep(i,n){
      ll a,b;
      cin>>a>>b;
      sum+=-b;
      cnt.push_back(a+b);
    }
    sort(begin(cnt),end(cnt),greater<ll>());
    rep(i,n){
      if(i%2==0) sum+=cnt[i];
    }
    cout<<sum<<endl;
}

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

using namespace std;

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

#define str string

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

    int k; str s;
    cin >> k >> s;
    int s_l = (int) s.length();
    if (s_l <= k) {
        cout << s << "\n";
    } else {
        cout << s.substr(0, k) << "...\n";
    }
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <tuple>
#include <math.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef tuple<int,int,int> P;


int main(){
    string S;
    cin >> S;
    if(S[0]!=S[1] || S[1]!=S[2]) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 3600
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mInt = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int op(int a,int b){
	return max(a,b);
}
int e(){
	return -1;
}
int t;
bool f(int a){
	return a<t;
}
int main(){
	
	int N,Q;
	cin>>N>>Q;
	vector<int> A(N);
	rep(i,N)cin>>A[i];
	
	segtree<int,op,e> seg(A);
	
	rep(i,Q){
		int T;
		cin>>T;
		
		if(T==1){
			int X,V;
			cin>>X>>V;
			seg.set(X-1,V);
		}
		if(T==2){
			int L,R;
			cin>>L>>R;
			cout<<seg.prod(L-1,R)<<endl;
		}
		if(T==3){
			int X,V;
			cin>>X>>V;
			t = V;
			
			cout<<seg.max_right(X-1,f)+1<<endl;
		}
	}
	
    return 0;
}

Measured memory_bytes: 6132
from collections import deque
 
n, q = map(int, input().split())
procs = deque([])
 
for i in range(n):
    name, time = input().split()
    time = int(time)
    procs.append([name, time])
total = 0
 
while procs:
    procs[0][1] -= q
 
    if procs[0][1] > 0:
        total += q
        procs.append(procs.popleft())
    else:
        total += q + procs[0][1]
        print(procs[0][0], total)
        procs.popleft()


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  // 割るレンガの最小
  // まず1がないと話にならないので、与えられたASの左から最初の1に至るまで全てを割る
  // 1がなかった場合は-1
  // 次は2に至るまで全部割ると言った要領
  int N;cin>>N;
  vector<int> AS(N);
  REP(i,N) cin>>AS[i];
  int tmp = 1;
  REP(i,N) {
    if (AS[i]==tmp) {
      tmp++;
    }
  }
  tmp==1 ? OUT(-1) : OUT(N-(tmp-1));

  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneoutofThree
{
    class OneoutofThree
    {
        static void Main(string[] args)
        {
            string[] strBuf = Console.ReadLine().Split(' ');

            var lst = new List<int>();

            lst.Add(int.Parse(strBuf[0]));
            lst.Add(int.Parse(strBuf[1]));
            lst.Add(int.Parse(strBuf[2]));


            if (lst[0] == lst[1])
            {
                Console.WriteLine(lst[2]);
                return;
            }

            if (lst[0] == lst[2])
            {
                Console.WriteLine(lst[1]);
            }
            else
            {
                Console.WriteLine(lst[0]);
            }

            return;

        }
    }
}


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

ll d = 1e9+7;
void comb(vector<vector <long long int> > &v){
	for(int i = 0;i <v.size(); i++){
		v[i][0]=1;
		v[i][i]=1;
	}
	for(int k = 1;k <v.size();k++){
		for(int j = 1;j<k;j++){
			v[k][j]=(v[k-1][j-1]+v[k-1][j])%d;
		}
	}
}


int main(void){
	int S;
	cin >> S;

	if (S == 1 || S == 2) {
		cout << 0 << endl;
		return 0;
	}

	int n = S/3;

	vector<vector<long long int> > v(2010,vector<long long int>(2010,0));
	comb(v);

	ll ans = 0;
	for (int i = 1; i<= n; i++) {
		ll t = S - 3*i;
		ans += v[t+i-1][i-1];
		ans %= d;
	}

	cout << ans << endl;

return 0;
}

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

int main() {
    int n;
    cin >> n;
    
    int a;
    int x=0;
    unordered_map<long long, long long> ump;
    for (int i=0; i<n; i++){
        cin >> a;
        x = max(x, a);
        ump[a]++;
    }

    long long c = 0;
    for (int i=-1; i<=x-1; i++){
        c = max(c, ump[i] + ump[i+1] + ump[i+2]);
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 4388
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cfloat>
using namespace std;
int mod = 1e9+7;
long long int inf = 1e18;

vector<bool> p;

vector<bool> func(int n){
  vector<bool> pp(n+1, false);
  for(int i=3; i<n; i+=2){
    if( p[i] && p[(i+1)/2] ){
      pp[i] = true;
    }
  }
  return pp;
}

vector<bool> isPrime(int n){
  vector<bool> p(n+1, true);
  p[0] = false;
  p[1] = false;
  for(int i=2; i<=sqrt(n); i++){
    if( !p[i] ) continue;
    for(int j=i+i; j<=n; j+=i){
      p[j] = false;
    }
  }
  return p;
}

int main() {
  int q;
  cin >> q;
  p = isPrime(100010);
  vector<bool> pp = func(100010);

  vector<int> s(100010, 0);
  for(int i=1; i<=100000; i++){
    s[i] = s[i-1];
    if( pp[i] ) s[i]++;
  }
  for(int i=0; i<q; i++){
    int l, r;
    cin >> l >> r;
    cout << s[r] - s[l-1] << endl;
  }

  return 0;
}

//


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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	double a, b, c;
	cin >> a >> b >> c;
	double s = 0.5 * a * b * sin(M_PI * c / 180);
	cout << setprecision(8) << fixed << s << '\n'
	 << a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(M_PI * c / 180)) << '\n'
	 << 2 * s / a << endl;
	return 0;
}



Measured memory_bytes: 3588
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
        m:i64,
        mut an:[i64;n],
        mut bcm:[(i64,i64);m],
    }
    an.sort();
    bcm.sort_by_key(|x|x.1);
    bcm.reverse();
    let mut sum:i64 = an.iter().sum();
    // // let change_sum = bcm.iter().map(|x|x.0).sum();
    // println!("{:?}",bcm);
    let mut change_index = 0;
    // let mut min = an.iter().min().unwrap();
    // println!("{}",sum);
    'outer: for &(mut b,c) in &bcm {
        if an[change_index] >= c {
            break;
        }
        while b > 0 {
            if an[change_index] >= c {
                break 'outer;
            }
            sum += c-an[change_index];
            // println!("{}",sum);
            b -= 1;
            change_index +=1;
            if change_index >= n as usize {
                break 'outer;
            }
        }
    }
    println!("{}",sum);
}

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

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 100003

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

  int freq[26] = {0};

  for(int i=1;i<=n;i++)
  	for(int j=1;j<=m;j++){
  		char c;
  		cin>>c;
  		freq[c-'a']++;
  	}

  int totalFours = 0 , totalTwos = 0 , totalOnes = 0;
  totalFours = (n/2) * (m/2);

  if(n&1){
  	totalTwos = (m/2);
  	if(m&1) totalOnes=1;
  }
  if(m&1){
  	totalTwos += (n/2);
  	if(n&1) totalOnes=1;
  }

  cerr<<totalFours<<" "<<totalTwos<<" "<<totalOnes<<endl;
  for(int i=0;i<26;i++){
  	while(freq[i] >= 4 && totalFours>0) totalFours-- , freq[i]-=4;
  	while(freq[i] >= 2 && totalTwos>0) totalTwos-- , freq[i]-=2;
  	while(freq[i] >=1 && totalOnes>0)  totalOnes-- , freq[i]--;
  }
  //cerr<<totalFours<<" "<<totalTwos<<" "<<totalOnes<<endl;
  if(totalTwos==0 && totalOnes ==0 && totalFours==0){
  	for(int i=0;i<26;i++){
  		if(freq[i]){
  			puts("No");
  			return 0;
  		}
  	}
  	puts("Yes");
  }
  else
  	puts("No");
  return 0;
}


void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}



Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<int> dp(n);
  for (int i = 1; i < n; ++i) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i >= 2) {
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }

  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
def readInt():
  return int(input())


def bubleSort(l, n):
    for i in range(1, n):
        for j in range(n - i):
            if l[j][1] > l[j + 1][1]:
                l[j], l[j + 1] = l[j + 1], l[j]
    return l


def selectionSort(l, n):
    for i in range(n):
        mini = i
        for j in range(i, n):
            if l[j][1] < l[mini][1]:
                mini = j
        l[i], l[mini] = l[mini], l[i]
    return l

def readInts():
  return [int(i) for i in input().split()]
N = readInt()
AS = input().split()

import copy

stable = bubleSort(copy.deepcopy(AS), N)
notstable = selectionSort(AS, N)

print(*stable)
print('Stable')
print(*notstable)
if stable == notstable:
    print('Stable')
else:
    print('Not stable')



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

int main(){
      int n,m;cin >> n >> m;
      char arr[n + 5][m + 5];
      for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                  cin >> arr[i][j];
            }
      }
      for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                  if(arr[i][j] == '#')cout << '#';
                  else{
                        int ans = 0;
                        for(int k = i - 1;k <= i + 1;k++){
                              if(k >= 0 && k < n){
                                    for(int l = j - 1;l <= j + 1;l++){
                                          if(l >= 0 && l < m){
                                                if(arr[k][l] == '#')ans++;
                                          }
                                    }
                              }
                        }
                        cout << ans;
                  }
            }
            cout << "\n";
      }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int H,W,A,B;
#define Maxn 1005
char ch[Maxn][Maxn];

int main(){
	scanf("%d%d%d%d",&H,&W,&A,&B);
	for(register int i=1;i<=B;++i){
		for(register int j=1;j<=A;++j)ch[i][j]='1';
		for(register int j=A+1;j<=W;++j)ch[i][j]='0';
	}
	for(register int i=B+1;i<=H;++i){
		for(register int j=1;j<=A;++j)ch[i][j]='0';
		for(register int j=A+1;j<=W;++j)ch[i][j]='1';
	}
	for(register int i=1;i<=H;++i){
		for(register int j=1;j<=W;++j)printf("%c",ch[i][j]);
		puts("");
	}
	return 0;
} 

Measured memory_bytes: 2176
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int calcAllArea(string in) {
    stack<int> s;
    int allArea = 0;

    for (int i = 0; i < in.length(); i++) {
        char c = in[i];

        switch (c) {
            case '\\':
                s.push(i);
                break;
            case '/':
                if (!s.empty()) {
                    allArea += i - s.top();
                    s.pop();
                }
                break;
            default:
                break;
        }
    }

    return allArea;
}

vector<int> calcPartialAreas(string in) {
    stack<int> s1;
    stack<pair<int, int>> s2;

    for (int i = 0; i < in.length(); i++) {
        char c = in[i];
        int s1Pos, area;

        switch (c) {
            case '\\':
                s1.push(i);
                break;
            case '/':
                if (!s1.empty()) {
                    s1Pos = s1.top();
                    s1.pop();
                    area = i - s1Pos;

                    while (!s2.empty() && s2.top().first > s1Pos) {
                        area += s2.top().second;
                        s2.pop();
                    }

                    s2.push(make_pair(s1Pos, area));
                }
                break;
            default:
                break;
        }
    }

    vector<int> partialAreas;
    while (!s2.empty()) {
        partialAreas.push_back(s2.top().second);
        s2.pop();
    }
    reverse(partialAreas.begin(), partialAreas.end());

    return partialAreas;
}

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

    int allArea = calcAllArea(in);
    cout << allArea << endl;

    vector<int> partialAreas = calcPartialAreas(in);
    cout << partialAreas.size();
    for (const auto &v : partialAreas) cout << " " << v;
    cout << endl;
}

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

char unko(int m, int f, int r){
	int sum = m + f;
	char grade;
	if(m == -1 || f == -1) grade = 'F';
	else if(sum >= 80) grade = 'A';
	else if(sum >= 65 && sum < 80) grade = 'B';
	else if(50 <= sum && sum < 65) grade = 'C';
	else if(30 <= sum && sum < 50){
		if(r >= 50) grade = 'C';
		else grade = 'D';
	}
	else if(sum < 30) grade = 'F';
	
	return grade;
}

int main() {
	int m, f, r;
	while (1){
		cin >> m >> f >> r;
		if ( m == -1 && f == -1 && r == -1 ) break;
		cout << unko(m, f, r) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n,m;
  int a,b,c;
  vector<pair<int,int> > way[SIZE];
  vector<pair<int,int> > ton;
  
  scanf("%d%d",&n,&m);

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&c);
    a--; b--;

    if(b == n-1){
      ton.push_back({a,c});
    }else{
      way[a].push_back({b,c});
    }
  }

  priority_queue<pair<int,int> > pq;
  bool visited[SIZE] = {};
  int memo[SIZE] = {};
  
  pq.push({0,0});

  while(pq.size()){
    pair<int,int> p = pq.top(); //[-time,place]
    pq.pop();

    if(visited[p.second]) continue;
    visited[p.second] = true;
    memo[p.second] = -p.first;

    for(int i=0;i<way[p.second].size();i++){
      if(-p.first <= way[p.second][i].second)
        pq.push({-way[p.second][i].second,way[p.second][i].first});
    }
  }

  int ans = -INF;
  
  for(int i=0;i<ton.size();i++){
    if(visited[ton[i].first] && memo[ton[i].first] <= ton[i].second){
      ans = max(ans,ton[i].second);
    }
  }

  if(ans == -INF)
    puts("-1");
  else
    printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 10232
import java.util.Scanner;
 
class Main {
  static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
		
       int X = sc.nextInt();
       long min=1192119211;
       int flag = 0;
       long nam = 0;
      
      for(int i=0;i<X;i++){
        long A = sc.nextLong();
        if(A<0){flag++;}
        nam += Math.abs(A);
        min = Math.min(min,Math.abs(A));
      }

	if(flag%2==0){System.out.print(nam);}
      else{System.out.print(nam-min*2);}
      
    }
}

Measured memory_bytes: 48260