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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; ll k; cin >> n >> k;
    ll kk = k; int mx = 0;
    while(kk){
        kk /= 2;
        mx++;
    }
    
    vll b(mx, 0);
    ll tot = 0;
    rep(i, n){
        ll a; cin >> a;
        tot += a;
        rep(j, mx){
            if(a & 1) b[j]++;
            a /= 2;
        }
    }
    
    ll x = 0, tmp = 0;
    rep3rev(j, mx - 1, 0){
        if(b[j] <= n/2) {
            if(x + (1LL << j) <= k) {
                x += (1LL << j);
                tmp += b[j] * (1LL << j); 
            }
        }
    }
    
    tot += ll(n) * x - 2 * tmp;
    cout << tot << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char **argv)
{

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		double th;

		int h, m;
		scanf("%d:%d", &h, &m);
		double a1 = h * 360 / 12 + m * 30.0 / 60.0;
		double a2 = m * 360 / 60;

		if (a1 > a2)
		{
			th = a1 - a2;
			if (th > 180)
				th = a2 + 360 - a1;
		}
		else // a1 <= a2 ?
		{
			th = a2 - a1;
			if (th > 180)
				th = a1 + 360 - a2;
		}

		if (th < 30)
			printf("alert\n");

		else if (th < 90) // 30 <= th < 90 ?
			printf("warning\n");

		else // 90 <= th <= 180 ?
			printf("safe\n");
	}

	return 0;
}

Measured memory_bytes: 1752
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = s.nextLong();
			b[i] = a[i] - (i+1);
		}
		Arrays.sort(b);
		long ans = 0;
		long bMid;
		if(n % 2 == 0) {
			bMid = (b[n/2] + b[(n/2) - 1]) / 2;
		}
		else {
			bMid = b[n/2];
		}
		for(int i = 0; i < n; i++) {
			ans += Math.abs(b[i] - bMid);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 85328
n, x, m = map(int, input().split())
mn = min(n, m)
S = set()
A = []
a = x
ans = 0
for i in range(mn):
    if a in S: break
    S.add(a)
    A.append(a)
    ans += a
    a = a*a%m
    if a == 0:
        print(ans)
        exit()

# print(S)
# print(A)
# print(len(A), n, m)
if len(A) < mn:
    st_len = 0
    while st_len < len(A) and a != A[st_len]: st_len += 1
    st = sum(A[:st_len])
    cyc_sum = sum(A[st_len:])
    cyc_len = len(A) - st_len
    cyc_num = (n - st_len) // cyc_len
    # print('m {} n {} st_len {} cyc_len {} cyc_num {}'.format(m,n,st_len,cyc_len,cyc_num))
    cyc = cyc_sum * cyc_num
    ed_len = (n - st_len) % cyc_len
    ed = sum(A[st_len:][:ed_len])
    print(st + cyc + ed)
else:
    print(ans)


Measured memory_bytes: 13764
N = int(input())
S = list(input())

black = S.count('#')
white = N - black

answer = 0
if (white > 0 and black > 0):
  answer = min(black, white)
  black_left = 0
  white_left = 0
  for i in range(N - 1):
    if (S[i] == '#'):
      black_left += 1
    else:
      white_left += 1
    black_right = black - black_left
    white_right = white - white_left
    answer = min(answer, black_left + white_right)

print(answer)


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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  int ans=d.size();
  for(int i=0; i<N-1; i++){
    if(d.at(i)==d.at(i+1)){
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  char henkan[1000];
  char ch,t_ch;
  while( cin >> n,n){
    for(int i = 0 ; i < 1000 ; i++ )henkan[i] = '\0';
  while(n--){
    cin >> ch >> t_ch;
    henkan[ ch ] = t_ch; 
  }
  cin >> n;
  while(n--){
    cin >> ch;
    if(henkan[ ch ] != '\0'){
      cout << henkan[ ch ]; 
    }else cout << ch;
  }
  cout << endl;
  }
}

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

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

    int n;
    cin >> n;
    vector<int> X(n), Y(n);
    REP(i, n){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y.begin(), Y.end());

    REP(i, n){
        if(X[i] <= Y[n / 2 - 1]) cout << Y[n / 2] << endl;
        else cout << Y[n / 2 - 1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3840
N,K = map(int,input().split(' '))

l = (N-1)*(N-2)//2
ans_l = []

if K>l:
    print(-1)
else:
    fixed = 2
    tmp = 3
    [ans_l.append([1,i]) for i in range(2,N+1)]

    for _ in range(l-K):
        ans_l.append([fixed,tmp])
        tmp += 1
        if tmp==N+1:
            fixed += 1
            tmp = fixed + 1
    print(N-1 + l-K)
    for a in ans_l:
        print(a[0],a[1])

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


struct Node {int parent,left,right;};
Node a[30];

void preorder(int i){
    if(i==-1)return;
    cout<<" "<<i;
    preorder(a[i].left);
    preorder(a[i].right);
}
void inorder(int i){
    if(i==-1)return;
    inorder(a[i].left);
    cout<<" "<<i;
    inorder(a[i].right);
}
void postorder(int i){
    if(i==-1)return;
    postorder(a[i].left);
    postorder(a[i].right);
    cout<<" "<<i;
}

int main(){
    int n;
    cin>>n;
    rep(i,n){
        a[i].parent=-1;
        a[i].left=-1;
        a[i].right=-1;
    }
    rep(i,n){
        int node,l,r;
        cin>>node>>l>>r;
        a[node].left=l;
        a[node].right=r;
        if(l>=0) {
            a[l].parent=node;
        }
        if(r>=0) {
            a[r].parent=node;
        }
    }
    int root;
    rep(i,n){
        if(a[i].parent==-1){
            root=i;
            break;
        }
    }
    cout<<"Preorder"<<endl;
    preorder(root);
    cout<<endl;
    cout<<"Inorder"<<endl;
    inorder(root);
    cout<<endl;
    cout<<"Postorder"<<endl;
    postorder(root);
    cout<<endl;
    
    return 0;

}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

pair<int,int> operator+(const pair<int,int> &lhs, const pair<int,int> &rhs){
  pair<int,int> p = { lhs.first + rhs.first, lhs.second + rhs.second };
  return p;
}

bool operator==(const pair<int,int> &lhs, const pair<int,int> &rhs){
  return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,cnt=0;
  cin>>H>>W;
  vector<string> S(H);
  vector<vector<int> > field(H, vector<int>(W,-1));
  queue<pair<int,int> > q;
  for(int i=0;i<H;i++){
    cin>>S[i];
    for(int j=0;j<W;j++){
      if(S[i][j]=='#')cnt++;
    }
  }
  field[0][0]=0;
  q.push(make_pair(0,0));

  const pair<int,int> moves[] = {
    { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 },
  };

  while( !q.empty() ) {
    pair<int,int> cur = q.front(); q.pop();
    for(auto &move : moves){
      pair<int,int> next=cur+move;
      if(next.first<0||next.first>=H||next.second<0||next.second>=W)continue;
      if(field[next.first][next.second]==-1 && S[next.first][next.second]!='#'){
        field[next.first][next.second]=field[cur.first][cur.second]+1;
        q.push(next);
      }
    }
  }
  if(field[H-1][W-1]==-1){
    cout<<-1<<endl;
  }else{
    cout<<H*W-1-field[H-1][W-1]-cnt<<endl;
  }
}


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

int h[200020], a[200020], dp[200020];

class SegmentTree {
private:
    int n;
    std::vector<long long> node;
    int def;
public:
    SegmentTree(std::vector<int> v, int d) : def(d){
        int sz = v.size();
        n = 1; while(n <= sz) n *= 2;
        node.resize(2*n, def);
        for(int i = 0; i < sz; i++){
            node[i+n] = v[i];
        }
        for(int i = n-1; i > 0; i--){
            node[i] = std::max(node[2*i], node[2*i+1]);
        }
    }
    void update(int i, long long val){
        node[i+n] = val;
        for(int j = (i+n)/2; j > 0; j/=2){
            node[j] = std::max(node[2*j], node[2*j+1]);
        }
    }
    long long getmax(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(b <= l || r <= a) return def;
        if(a <= l && r <= b) return node[k];
        long long vl = getmax(a, b, 2*k, l, (l+r)/2);
        long long vr = getmax(a, b, 2*k+1, (l+r)/2, r);
        return std::max(vl, vr);
    }
};


int main(){
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        std::cin >> h[i];
    }
    SegmentTree segmentTree(std::vector<int>(n,0), 0);
    for(int i = 0; i < n; i++){
        int a; std::cin >> a;
        segmentTree.update(h[i]-1, segmentTree.getmax(0, h[i]-1) + a);
    }
    std::cout << segmentTree.getmax(0,n) << std::endl;
}


Measured memory_bytes: 5888
import java.util.Scanner;

public class Main {

	public static void solve (String[] map) {
		int x = 0, y = 0;
		boolean[][] check = new boolean[map.length][map[0].length()];
		while (map[y].charAt(x) != '.') {
			if (check[y][x]) {
				System.out.println("LOOP");
				return;
			} else
				check[y][x] = true;
			char c = map[y].charAt(x);
			if (c == '^')
				y--;
			else if (c == 'v')
				y++;
			else if (c == '>')
				x++;
			else
				x--;
		}
		System.out.println(x + " " + y);
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {
			String[] str = sc.nextLine().split(" ");
			int h = Integer.parseInt(str[0]);
			int w = Integer.parseInt(str[1]);
			if (w == 0 && h == 0) break;
			String[] map = new String[h];
			for (int i = 0; i < h; i++) {
				map[i] = sc.nextLine();
			}
			solve(map);
		}

	}

}

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

int main() {
	string s, t;
	cin >> s >> t;
	int ans[s.size()+1][t.size()+1];
	for(int i=0; i<=s.size(); i++){
	    ans[i][0] = 0;
	}
	for(int i=0; i<=t.size(); i++){
	    ans[0][i] = 0;
	}
	for(int i=1;i<=s.size();i++){
	    for(int j=1;j<=t.size();j++){
	        if(s[i-1] == t[j-1]){
	            ans[i][j] = ans[i-1][j-1] + 1;
	        }else{
	            ans[i][j] = max(ans[i][j-1],ans[i-1][j]);
	        }
	    }
	}
    // for(int i=0;i<=s.size();i++){
	//     for(int j=0;j<=t.size();j++){
	//         cout<<ans[i][j]<< " ";
	//     }
	//     cout<<"\n";
	// }
	int n = s.size(), m = t.size();
	int result = ans[s.size()][t.size()];
	char res[result+1];
	res[result] = '\0';
    int i = n, j = m;
	while(result){
	    // if(ans[n][m-1] != result){
	    //     cout << m <<" ";
	    //     res[--result] = t[m-1];
	    //     // n--;
	    // }
	    // m--;
        if(s[i-1]==t[j-1]){
            // cout<<j<<" ";
            i--;
            j--;
            result--;
            res[result] = t[j];
        }else{
            if(ans[i-1][j]>ans[i][j-1]){
                i--;
            }else{
                j--;
            }
        }
	}
	string p = "";
	cout << res;
	//cout << ans[s.size()][t.size()];
	return 0;
}

Measured memory_bytes: 38776
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

typedef long long LL;
using namespace std;

#define MAXN 5005*5005
#define int LL

int ti[5];
int v[5];
int dp[MAXN];

signed main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	scanf("%lld", &n);
	int t = n, m = 3;
	for (int j = 1; j <= m; j++) {
		scanf("%lld", &ti[j]);
	}
	for (int j = 1; j <= m; j++) {
		scanf("%lld", &v[j]);
	}
	v[4] = 1;
	ti[4] = 1;
	for (int j = 1; j <= 4; j++) {
		//if (j > 3) break;
		for (int k = ti[j]; k <= t; k++) {//卧槽太有道理了，这个时候正向更新，就是为了能够重复放入
			//if (j > 3) break;
			dp[k] = max(dp[k], dp[k - ti[j]] + v[j]);//一维后dp[k]而不是dp[k-1]
		}
	}
	int l = dp[t];
	for (int i = 1; i <= t; i++) {
		dp[i] = 0;
	}
	t = l;
	for (int i = 1; i <= 3; i++) {
		int temp = ti[i];
		ti[i] = v[i];
		v[i] = temp;
	}
	for (int j = 1; j <= 4; j++) {
		//if (j > 3) break;
		for (int k = ti[j]; k <= t; k++) {//卧槽太有道理了，这个时候正向更新，就是为了能够重复放入
			//if (j > 3) break;
			dp[k] = max(dp[k], dp[k - ti[j]] + v[j]);//一维后dp[k]而不是dp[k-1]
		}
	}
	printf("%lld", dp[t]);
	return 0;
}


Measured memory_bytes: 195584
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+4;

int main(){
	string S;
	cin>>S;
	int p[4];
	p[0]=8,p[1]=6,p[2]=4,p[3]=0;
	
	bool ans=false;
	for(int a=0;a<(1<<4);a++){
		string T={"AKIHABARA"};
		rep(i,4){
			if(a & (1<<i))T.erase(T.begin()+p[i]);
		}
//      	cout<<T<<endl;
		if(T==S)ans=true;
	}
	if(ans)cout<<"YES";
	else cout<<"NO";
}

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

using namespace std;

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

typedef long long ll;

ll gcd(ll a,ll b){

  while(a%b){
    ll r=a%b;
    a=b;
    b=r;
  }
 return b;
}

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

 ll a,b;
  cin >> a >> b;
  
  ll g=gcd(a,b);
  
  ll res=1;
  
  if(g%2==0) {res++;
  while(g%2==0) g/=2;
               }
  
  for(ll i=3;i*i<=g;i+=2){
    if(g%i!=0) continue;
     res++;
    while(g%i==0) g/=i;
  } 
  
  if(g!=1) res++;
 
  cout << res << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n;
    long long k;
    cin >> n >> k;
    long long num[100001] = {0};
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        num[a] += b;
    }
    for (int i = 1; i <= 100000; i++) {
        if (k <= num[i]) {
            cout << i << endl;
            break;
        }
        k -= num[i];
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x0123456789) cerr<<#x0123456789<<':'<<x0123456789<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x0123456789:v)cerr<<x0123456789<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

struct Graph{
  long long V;
  long long E;
  //u,v,weight,cap
  vector<tuple<long long,long long,long long,long long>> edges;
  void add(long long u,long long v,long long weight){edges.push_back(make_tuple(u,v,weight,0));}
  void add(long long u,long long v,long long weight,long long capacity){edges.push_back(make_tuple(u,v,weight,capacity));}
};

//最大フロー
long long max_flow(const Graph &G,const long long &start,const long long &end){long long cf[G.V][G.V],ans=0;for(long long i=0;i<G.V;i++)for(long long j=0;j<G.V;j++)cf[i][j]=0;for(long long i=0;i<G.E;i++)cf[get<0>(G.edges[i])][get<1>(G.edges[i])]=get<3>(G.edges[i]);queue<long long> que;while(1){que.push(start);long long dmin[G.V];for(long long i=0;i<G.V;i++)dmin[i]=-1;dmin[start]=0;while(que.size()){long long n=que.front();for(long long i=0;i<G.V;i++){if(n!=i&&cf[n][i]>0&&dmin[i]==-1){dmin[i]=n;que.push(i);}}que.pop();}if(dmin[end]==-1)break;vector<long long> way;long long n=end;while(n!=start){way.push_back(n);n=dmin[n];}way.push_back(start);long long MIN=1000000007;for(long long i=0;i<way.size()-1;i++)MIN=min(MIN,cf[way[i+1]][way[i]]);for(long long i=0;i<way.size()-1;i++){cf[way[i]][way[i+1]]+=MIN;cf[way[i+1]][way[i]]-=MIN;}ans += MIN;}return ans;}

signed main(){
    ll N;
    cin >> N;
    Graph G;
    G.V = 2*N+2;
    ll a[2*N],b[2*N];
    FOR(i,0,N*2)cin >> a[i] >> b[i];
    FOR(i,0,N)FOR(j,N,2*N){
        if(a[i]<a[j]&&b[i]<b[j]){
            G.add(i,j,0,1);
        }
    }
    FOR(i,0,N){
        G.add(2*N,i,0,1);
    }
    FOR(j,N,N*2){
        G.add(j,2*N+1,0,1);
    }
    G.E = G.edges.size();
    cout << max_flow(G,2*N,2*N+1) << endl;
}

Measured memory_bytes: 768
package main

import "fmt"

func primeFactor(n int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			ret[i]++
			n /= i
		}
	}
	if n != 1 {
		ret[n] = 1
	}
	return ret
}

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for _, v := range primeFactor(n) {
		for i := 1; v >= i; i++ {
			v -= i
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1832
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<cmath>
#include<string>

using namespace std;

int main()
{
    string s;

    cin >> s;
    int min = 10000;
    for (int i = 0; i < s.size() - 2; i++) {
        string s2 = s.substr(i, 3);
        int x = atoi(s2.c_str());
        int y = abs(753 - x);

        if (min > y)min = y;

        
    }
    cout << min << endl;

    return 0;
}



Measured memory_bytes: 3596
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

def divisors(n):
    m = 1
    divs = []
    while m * m <= n:
        if n % m == 0:
            divs.append(m)
            if n != m * m:
                divs.append(n // m)
        m += 1
    divs.sort()
    return divs
  
N = int(read())

cnt = 0
for i in range(1, N+1, 2):
  if len(divisors(i)) == 8:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
using namespace std;

int main(){

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

    int n,i;
    cin >> n;

    string s,t;
    string ans;
    cin >> s;
    cin >> t;

    for(i = 0; i < n; i++){
        ans = ans + s[i] + t[i];

    } 
    cout << ans;
}

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

using namespace std;

int A, B, C, D, E, F;
int ans_s, ans_w;
double mx;

void solve() {
    int na = F / (100 * A);
    int nb = F / (100 * B);
    int nc = F / C;
    int nd = F / D;

    //cout << na << " " << nb << " " << nc << " " << nd << endl;

    for (int a = 0; a <= na; a++) {
        for (int b = 0; b <= nb; b++) {
            for (int c = 0; c <= nc; c++) {
                for (int d = 0; d <= nd; d++) {
                    int w = a * 100*A + b * 100*B;
                    int s = c * C + d * D;
                    //cout << F << " <>" << w << "+" << s << endl;
                    if (F < w + s) continue;
                    if (w/100 * E < s) continue;
                    if (1.0 * s / (s + w) <= mx) continue;
                    mx = 1.0 * s / (s + w);
                    ans_s = s;
                    ans_w = w;
                }
            }
        }
    }

    cout << ans_s + ans_w << " " << ans_s << endl;
}

int main() {
    cin >> A >> B >> C >> D >> E >> F;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
inline int min(int a, int b) { return a < b ? a : b; }
inline int abs(int n) { return n < 0 ? -n : n; }
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  int mi = 2e9;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    mi = min(mi, abs(t));
    sum += abs(t);
    cnt += (t <= 0);
  }
  cout << (cnt % 2 ? sum - 2 * mi : sum) << endl;
}

Measured memory_bytes: 256
use strict;
use warnings;
use utf8;

# X(i+1)=rxi - D

my ($r, $D, $x2k) = split /\s/, <STDIN>;

for (1 .. 10) {
    my $x = $r * $x2k - $D;
    printf "%d\n", $x;
    $x2k = $x;
}


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

#define ll long

using namespace std;

int main()
{
    ll x, y, a, b, c;

    cin >> x >> y >> a >> b >> c;

    vector<ll> p(a), q(b), r(c), res;

    for (ll i = 0; i < a; i++)
    {
        cin >> p[i];
    }
    for (ll i = 0; i < b; i++)
    {
        cin >> q[i];
    }
    for (ll i = 0; i < c; i++)
    {
        cin >> r[i];
    }

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    ll ind = 0;
    ll count = x;
    while (count)
    {
        res.push_back(p[ind]);
        ind++;
        count--;
    }

    ind = 0;
    count = y;
    while (count)
    {
        res.push_back(q[ind]);
        ind++;
        count--;
    }

    for(ll i = 0; i < r.size(); i++){
        res.push_back(r[i]);
    }

    sort(res.begin(), res.end(), greater<ll>());
    ll result = 0;

    for(ll i = 0; i < x + y; i++){
        result += res[i];
    }
    // i = 0;
    // ll j = 0;

    // while (i < res.size() && j < c)
    // {
    //     if (r[j] > res[i])
    //     {
    //         res[i] = r[j];
    //         i++;
    //         j++;
    //     }
    //     else
    //     {
    //         break;
    //     }
    // }

    // ll result = accumulate(res.begin(), res.end(), 0);
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 8432
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()

ll dp[110][4][4][4];

int main()
{
	int n; cin >> n;
	ll MOD = 1e9 + 7;
	rep(i, 110)rep(j, 4)rep(k, 4)rep(l, 4)dp[i][j][k][l] = 0;
	dp[0][3][3][3] = 1;
	for (int i = 1; i <= n ; ++i)
	{
		rep(j, 4)
		{
			switch (j)
			{
			case 1:
				rep(a, 4)rep(b, 4)rep(c, 4)
				{
					if (a == 0 && c == 2)continue;
					if (a == 0 && b == 2)continue;
					if (b == 2 && c == 0)continue;
					if (b == 0 && c == 2)continue;
					dp[i][b][c][j] += dp[i - 1][a][b][c];
					dp[i][b][c][j] %= MOD;
				}
				break;
			case 2:
				rep(a, 4)rep(b, 4)rep(c, 4)
				{
					if (b == 0 && c == 1)continue;
					dp[i][b][c][j] += dp[i - 1][a][b][c];
					dp[i][b][c][j] %= MOD;
				}
				break;
			default:
				rep(a, 4)rep(b, 4)rep(c, 4)
				{
					dp[i][b][c][j] += dp[i - 1][a][b][c];
					dp[i][b][c][j] %= MOD;
				}
				break;
			}
		}
	}
	ll res = 0;
	rep(i, 4)rep(j, 4)rep(k, 4)
	{
		res += dp[n][i][j][k];
		res %= MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
/*786*/
#include<bits/stdc++.h>
#define        ll          long long int
#define        sj          200010
#define        fast        ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define        sc1(a)      scanf("%lld",&a)
#define        sc2(a,b)    scanf("%lld %lld",&a,&b)
#define        pb          push_back
#define        pn          printf("No\n")
#define        py          printf("Yes\n")
#define        op(a)       printf("%lld\n",a)

using namespace std;



int main()
{

    long  double a,b,x;
     cin>>a>>b;
     x=a*b;
     ll d=x;

     cout<<d<<endl;

    return 0;
}







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

int main() {
  char c;
  int a;
  a = 0;
  cin >> c;
  if(c=='a'){
    cout << "vowel" <<endl;
    a++;
  }
   if(c=='i'){
    cout << "vowel" <<endl;
     a++;
  }
   if(c=='u'){
    cout << "vowel" <<endl;
     a++;
  }
 if(c=='e'){
    cout << "vowel" <<endl;
   a++;
  }
 if(c=='o'){
    cout << "vowel" <<endl;
   a++;
  }
  if(a==0){
    cout << "consonant" << endl;
  }



    
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
#define M_INF -1000000000
typedef long long int ll;

int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll ans=1+(N-2)*(B-A);
    if(ans<0){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}
    

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  string s;
  cin >> N>> s;
  int cnt = 0;

  int ans = 0;
  for (auto c : s) {
    if (c == 'I') ++cnt;
    else --cnt;

    chmax(ans, cnt);
  }

  cout << ans << endl;
  return 0;
}



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

int f(int i, int n, vector<int>& h, vector<int>& dp) {
    if (i == n - 1) return 0;
    int& ans = dp[i];
    if (ans != -1) return ans;
    ans = abs(h[i] - h[i + 1]) + f(i + 1, n, h, dp);
    if (i + 2 < n) ans = min(ans, abs(h[i] - h[i + 2]) + f(i + 2, n, h, dp));
    return ans;
}

void solve(int test) {
    int n;
    cin >> n;
    vector<int> h(n), dp(n, -1);
    for (int i = 0; i < n; i++) cin >> h[i];
    cout << f(0, n, h, dp) << "\n";
}

int main(){
#ifdef VPAL
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    for (int test = 1; test <= t; test++) {
        solve(test);
    }
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;

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

int main(){
    int H,W,N;
    cin >> H >> W >> N;

    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
        //printf("a[%d] = %d",i,a[i]);
    }

    int c[H][W];
    for(int i=0; i<H; i++){
        for(int j =0; j<W; j++){
            c[i][j] = 0;
        }
    }

    int move_num = 0;
    int x = 0;
    int y = 0;

    for(int i = 0; i < N; i++){
        //printf("*****************%d***************\n",i);
        for(int j = 0; j < a[i]; j++){
            //printf("---------------\n");
                c[y][x] = i+1;
                //printf("c[%d][%d] = %d\n",y,x,c[y][x]);
                //printf("move_num = %d\n",move_num);
                //printf("dx,dy = %d,%d\n",dx[move_num],dy[move_num]);
                if(x+dx[move_num] > W-1 or y+dy[move_num] > H-1){
                    //printf("Yo! over the HW\n");
                    move_num++;
                    if(move_num == 4){
                        move_num = 0;
                    }
                }
                if(c[y+dy[move_num]][x+dx[move_num]] != 0){
                    //printf("Hey! already paint\n");
                    move_num++;
                    if(move_num == 4){
                        move_num = 0;
                    }
                }
                x += dx[move_num];
                y += dy[move_num];
            }

        }

    string S[H];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            S[i] += to_string(c[i][j]);
            S[i].push_back(' ');
        }
        cout << S[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 384
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

a,b = input().split()

a,b = int(a*int(b)),int(b*int(a))
print(max([a,b]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n , m , c;
    cin>>n>>m>>c;
    int barr[m];
    for(int i = 0 ; i<m ; i++){
        cin>>barr[i];
    }
    int cnt = 0; 
    for(int i = 0 ; i<n ; i++){
        int arr[m];
        int sum = 0;
        for(int j = 0 ; j<m ; j++){
            cin>>arr[j];
            sum+= (arr[j] * barr[j]);
        }
        sum+=c;
        if(sum >0){
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
Y /= 1000
res10 = res5 = res1 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10*x + 5*y + z == Y:
            res10 = x
            res5 = y
            res1 = z
print(str(res10)+" "+str(res5)+" "+str(res1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		arr[i] = a;
	}
	ll sum1=0; ll sum=0;
	ll op1=0; ll op2=0;
	for(int i=0;i<n;i++){
		sum += arr[i];
		if(i%2==0){
			if(sum<=0){
				op1 += abs(sum)+1;
				sum = 1; 
			}
		}
		else{
			if(sum>=0){
				op1 += abs(sum)+1;
				sum =-1;
			}
		}
	}
	sum=0;
	for(int i=0;i<n;i++){
		sum += arr[i];
		if(i%2==0){
			if(sum>=0){
				op2 += abs(sum)+1;
				sum = -1; 
			}
		}
		else{
			if(sum<=0){
				op2 += abs(sum)+1;
				sum = 1;
			}
		}
	}
	cout<<min(op1,op2)<<endl;
}

Measured memory_bytes: 1024
//#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

const int nmax = 50;
int v[nmax + 1];

pair<int, int> ord[nmax + 1];

vector<pair<int, int>> sol;

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

    for (int i = 1; i <= n; ++ i) {
        cin >> v[ i ];
        ord[ i ] = make_pair(v[ i ], i);
    }
    sort(ord + 1, ord + n + 1);

    if (ord[ 1 ].first < 0 && ord[ n ].first > 0) {
        int x = ord[ 1 ].second;
        if (abs(ord[ 1 ].first) < ord[ n ].first) {
            x = ord[ n ].second;
        }

        for (int i = 1; i <= n; ++ i) {
            v[ i ] += v[ x ];
            sol.push_back(make_pair(x, i));
        }
    }

    int pos = 0;
    for (int i = 1; i <= n; ++ i) {
        if (v[ i ] > 0)
            pos = 1;
    }

    if (pos == 1)
        for (int i = 1; i < n; ++ i)
            sol.push_back(make_pair(i, i + 1));
    else
        for (int i = n; i > 1; -- i)
            sol.push_back(make_pair(i, i - 1));

    cout << sol.size() << "\n";
    for (auto i : sol)
        cout << i.first << " " << i.second << "\n";

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(5);
    string s,s1,s2;
    cin >> n >> x >> s;
    c = 'a' - 'A';
    s[x-1] += c;  
    cout << s << endl;
    return 0;
} 

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

vector<ll> A;

int main() {
    ll N, a,b;
    cin >> N >> a>>b;
    A.resize(N);
    rep(i,N) cin >> A[i];
    ll ans=0;
    rep(i,N-1){
        ll dis=A[i+1]-A[i];
        ans+=min(dis*a,b);
    }
    cout << ans << endl;
}


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

int t,c,n,mn,mx;
string s,q;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b+c>=22){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }
}


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

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 llINF = 1LL << 60;
const int iINF = 1e8;

//---main---------------------------------------------
int main(){
    //main
    int N;
    ll D;
    cin >> N >> D;
    ll D2 = D*D;


    int ans = 0;
    ll x,y;
    rep(i,N){
        cin >> x >> y;
        if(x*x+y*y <= D2) ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)):
        for i, x_time in enumerate(cum_x, 1):
            if x_time > K:
                candidates.append(0)
                break
            y_time = K - x_time
            candidates.append(i + bisect(cum_y, y_time))
    print(max(candidates))


if __name__ == "__main__":
    main()


Measured memory_bytes: 58144
#include <cstdio>
#define Int register int

static inline char Get_Char() {
	static char buffer[100000], *S = buffer, *T = buffer;
	if (S == T) {
		T = (S = buffer) + fread(buffer, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}

//#define Get_Char() getchar()

static inline int Read() {
	int f = 1, x = 0;
	register char sign = Get_Char();
	for (; sign > '9' || sign < '0'; sign = Get_Char())
		if (sign == '-') f = -1;
	for (; sign >= '0' && sign <= '9'; sign = Get_Char())
		x = (x << 3) + (x << 1) + (sign ^ 48);
	return x * f;
}

int main() {
	int m = Read(), d = Read(), Ans = 0;
	
	for (Int i = 1, x, y, num; i <= m; ++ i) {
		for (Int j = 22; j <= d; ++ j) {
			num = j;
			x = num % 10;
			if (x < 2) continue;
			num /= 10;
			y = num % 10;
			if (x * y == i)
				++Ans;
		} 
	}
	printf("%d\n", Ans);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define BE(x) x.begin(), x.end()

int main() {
    int k;
    cin >> k;
    string s = "ACL";
    for (int i = 0; i < k; i++) {
        cout << s ;
    }
    cout << endl;
}

Measured memory_bytes: 3584
from itertools import accumulate
from collections import defaultdict
n,m = map(int, input().split())
As = list(map(int, input().split()))
acc = list(accumulate([0]+As))
amari = [a%m for a in acc]


# あまりが0になるものを抜粋していく
d = defaultdict(int)
for a in amari:
    d[a] += 1
ans = 0
for k in d.keys():
    x = d[k]
    ans += x*(x-1)//2
print(ans)

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

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<pair<ll, ll>> a(n);
    for(ll i=0;i<n;++i){
        ll b;
        cin>>b;
        a[i] = make_pair(b, i+1);
    }
    sort(a.begin(), a.end());

    for(ll i=0;i<n;++i){
        if(i != 0){
            cout<<' ';
        }
        cout<<a[i].second;
    }
    cout<<endl;
    return 0;
}

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

int main(){

  long ans=0, X, num=0;
  cin >> X;

  for(int i=1; i<=X; i++){
    num += i;
    if(num >= X){
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define Debug(x) x
typedef int regular_int;
// #define int ll
typedef long long ll;

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	int N, K;
	string s;
	cin >> N >> K >> s;
	int cnt = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < N - 1; ++i) {
        if (s[i] == 'L' && s[i + 1] == 'R')
            ++cnt2;
         else if (s[i] == 'R' && s[i + 1] == 'L')
            ++cnt3;
          else
            ++cnt;
	}
	int x = min(min(cnt2, cnt3), K);
	cnt2 -= x;
	cnt3 -= x;
	K -= x;
	cnt += 2 * x;
	cout << min(N - 1, cnt + K) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

void insertionSort(int *, int, int);
int shellSort(int *, int);

int cnt = 0;
int G[100];

int main() {
  int i;
  int a[1000000];
  int n, m;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);
  
  m = shellSort(a, n);

  printf("%d\n", m);
  for(i = m - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if(i > 0) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  
  for(i = 0; i < n; i++)
    printf("%d\n", a[i]);
  
  return 0;
}

void insertionSort(int *A, int n, int g) {
  int i, j, key;

  for(i = g; i < n; i++) {
    key = A[i];
    j = i - g;
    while(j >= 0 && A[j] > key) {
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = key;
  }
}

int shellSort(int *A, int n) {
  int i, r;

  G[0] = 1;
  for(i = 1; ; i++) {
    if(G[i-1] > n) break;
    G[i] = 3 * G[i-1] + 1;
  }
  
  r = i - 1;

  for(i = r; i >= 0; i--) {
    insertionSort(A, n, G[i]);
  }

  return r;

}

Measured memory_bytes: 4512
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#define INF (1e9)
#define P 25
#define N 50
using namespace std;
double cal(int,int);
int r,n,xl,xr,h,le,ri;

int main(){
  double ans;
  bool d1[N][N],d[N][N];
  while(1){
    cin>>r>>n;
    if(!r&&!n) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++) d1[i][j]=d[i][j]=false;
    while(n--){
      cin>>xl>>xr>>h;
      for(int i=0;i<h;i++)
	for(int j=xl+P+1;j<=xr+P;j++) d1[i][j]=true;
    }
    for(int i=0;i<N;i++)
      for(int j=0;j<N-1;j++)
	if(d1[i][j]){
	  if(!i&&d1[i][j+1]) d[i][j]=true;
	  if(i&&d1[i][j+1]&&d1[i-1][j]&&d1[i-1][j+1]) d[i][j]=true;
	}
    le=P-(r-1);
    ri=P+(r-1);
    ans=INF;
    for(int i=le;i<=ri;i++)
      for(int j=0;j<N;j++)
	if(!d[j][i]){
	  ans=min(ans,cal(P-i,j));
	  break;
	}
    printf("%.4f\n",ans);
  }
  return 0;
}

double cal(int x,int p){
  return r-sqrt(r*r-x*x)+p;
}

Measured memory_bytes: 1200
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
#print(a)
#print(b)
#print(c)
pat=0
ikeep=-1
for i in range(n):
  x=b[i]
  if(x!=ikeep):
    ikeep=x
  else:
    pat+=paty*patz
    continue
  paty=bisect.bisect_left(a,x)
  patz=n-bisect.bisect_right(c,x)
  #print(paty,patz)
  pat+=paty*patz
print(pat)

Measured memory_bytes: 23360
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s;
  cin >> s;
  ll q;
  cin >> q;
  bool reversed = false;
  rep(i, q) {
    ll t;
    cin >> t;
    if (t == 1) {
      reversed = !reversed;
    } else {
      ll f;
      cin >> f;
      char c;
      cin >> c;
      if (reversed) {
        if (f == 1) f = 2;
        else f = 1;
      }
      if (f == 1) {
        s.insert(s.begin(), c);
      } else {
        s.push_back(c);
      }
    }
  }
  if (reversed) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string x;
	cin >> x;
	
	int n = (int)x.size();
	int ans = n;
	int s = 0, t = 0;
	bool sflag = false, tflag = false;
	
	for(int i = 0; i < n; ++i) {
		if( x[i] == 'S' ) {
			if( tflag ) {
				ans -= 2 * min(s, t);
				s = max(0, s - min(s, t)), t = 0;
				tflag = false;
			}
			
			s++;
			sflag = true;
			
		} else if( x[i] == 'T' && sflag && s > t ) {
			t++;
			tflag = true;
		}
	}
	
	if( sflag && tflag ) {
		while( s != 0 && t != 0 ) {
			ans -= 2 * min(s, t);
			s = max(0, s - min(s, t)), t = max(0, t - min(s, t));
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  rep(i, s.size()) cout << "x";
  cout << endl;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(AB[0] + AB[1] < 10 ? (AB[0] + AB[1]).ToString() : "error");
        }
    }
}


Measured memory_bytes: 11348
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		sc.close();

		int[] cnt = new int[26];
		int b = a.length();
		for (int i = 0; i < b; i++) {
			cnt[a.charAt(i) - 'a']++;
		}

		long ans = (long) b * (b - 1) / 2 + 1;
		for (int i = 0; i < 26; i++) {
			long c = (long) cnt[i] * (cnt[i] - 1) / 2;
			ans -= c;
		}
		System.out.println(ans);
	}
}


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

int P[1001], mem[1001 * 1001], N, M;
int main()
{
loop:
  cin >> N >> M;
  if(!N)
    return 0;
  N++;
  P[0] = 0;
  for(int i = 1; i < N; i++)
    cin >> P[i];
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
      mem[N * i + j] = P[i] + P[j];
  sort(mem, mem + N * N);

  int ans = 0;
  for(int i = 0; i < N * N; i++)
  {
    if(mem[i] > M)
      continue;
    ans = max(ans, mem[i] + *(upper_bound(mem, mem + N * N, M - mem[i]) - 1));
  }
  cout << ans << endl;
  goto loop;
}

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


int main() {

	int N;
	string S;
	cin >> N >> S;

	int count = 0;
	for (int i = 1;i < N;i++) {
		if (S.at(i) != 'W')
			count++;
	}
	int ans = count;
	for (int i = 1;i < N;i++) {
		if (S.at(i - 1) == 'E' && S.at(i) == 'E') {
			count--;
		}
		if (S.at(i - 1) == 'W' && S.at(i) == 'W') {
			count++;
		}
		ans = min(ans, count);
	}

	cout << ans;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    string x;
    cin >> x;
    int s_count = 0;
    int ret = 0;
    for (int i = 0; i < x.length(); i++) {
        if (x[i] == 'T') {
            if (s_count == 0) {
                ret++;
            }
            else {
                s_count--;
            }
        }
        else {
            s_count++;
        }
    }
    cout << ret + s_count << endl;
    return 0;
}

Measured memory_bytes: 3608
#include "iostream"
#include "math.h"
using namespace std;

int main()
{
    long int n;
    int m;

    cin >> n >>m;
    int a[m];
    long int sum=0;
    for(int i=0;i<m;i++)
    {
        cin >>a[i];
        sum += a[i];
    }
    if(n-sum >=0)
    {
        cout <<n-sum<<endl;
    }

    else if(n-sum < 0)
    {
        cout << "-1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int cnt=0;
		double[][] a = new double[20][2];
		while(cin.hasNext()){
			String[] s = cin.next().split(",");
			a[cnt][0]=Double.parseDouble(s[0]);
			a[cnt][1]=Double.parseDouble(s[1]);
			cnt++;
		}
		Pair[] p = new Pair[cnt];
		for(int i = 0;i<cnt;i++){
			p[i]=new Pair(a[i][0],a[i][1]);
		}
		double ans=0.0;
		for(int i = 1;i<cnt-1;i++){
			ans+=p[0].s(p[i], p[i+1]);
		}
		System.out.println(ans);
	}
}
class Pair{
	double x,y;
	Pair(double a,double b){
		x=a;y=b;
	}
	double s(Pair p,Pair q){
		Pair r = this;
		double a = dist(p,q);
		double b = dist(p,r);
		double c = dist(q,r);
		double z = (a+b+c)/2.0;
		
		return Math.sqrt(z*(z-a)*(z-b)*(z-c));
	}
	double dist(Pair p,Pair q){
		double a = (p.x-q.x)*(p.x-q.x);
		double b = (p.y-q.y)*(p.y-q.y);
		return Math.sqrt(a+b);
	}
}

Measured memory_bytes: 12000
while true do
  input = STDIN.gets
  x_y = input.split(" ")
  x = x_y[0].to_i
  y = x_y[1].to_i
  if (x == 0) && (y == 0)
    break
  end
  
  if x < y then
    print x.to_s + " " + y.to_s + "\n"
  else
    print y.to_s + " " + x.to_s + "\n"
  end
end

Measured memory_bytes: 8724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int  main(){
    int n,sum=0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int i=0;
    while(i<n){
        int t=0,tmp=a[i];
        while(i<n && tmp==a[i]){
            i++;
            t++;
        }
        sum+=t%2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640