akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
// const ll MOD = 1000000007;

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

	int n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	ll dp[n][n];
	int flag = n&1;
	for(int i=0;i<n;i++){
		if(flag)
			dp[i][i] = a[i];
		else
			dp[i][i] = -a[i];
	}

	for(int k=1;k<n;k++){
		flag = 1-flag;
		for(int i=0;i<n-k;i++){
			if(flag)
				dp[i][i+k] = max(dp[i][i+k-1]+a[i+k],dp[i+1][i+k]+a[i]);	
			else
				dp[i][i+k] = min(dp[i][i+k-1]-a[i+k],dp[i+1][i+k]-a[i]);
		}
	}
	
	cout<<dp[0][n-1]<<endl;
}


Measured memory_bytes: 70272
N, M, C = [int(c) for c in input().split()]

B = [int(c) for c in input().split()]

count = 0
for _ in range(N):
    A = [int(c) for c in input().split()]
    if sum(a*b for a, b in zip(A, B)) + C > 0:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    while(1){
        string s; cin>>s;
        if(s == "0") return 0;

        int a = 0;
        int b = 0;
        for(int i=1; i<s.size(); i++){
            if(s[i] == 'A') a++;
            else b++;
        }

        if(a < b){
            b++;
        }
        else{
            a++;
        }

        cout << a << " " << b << endl;
    }
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 200005

int n;
int a[MAXX];
int b[MAXX];

int main()
{
    _FastIO;

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[a[i]] = i;
    }
    int m = n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        m = min(m , b[i]);
        if(m == b[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

void init(const list<int>::iterator&begin, const list<int>::iterator&end) {
	auto itr = begin;
	for (int i = 0; itr != end; ++i) {
		*itr = i;
		++itr;
	}
}
signed main()
{
	int n, m;
	while (cin >> n >> m, n) {
		list<int>p(n); init(ALL(p));
		auto potate = prev(p.end());
		while (p.size() > 1) {
			REP(i, m) {
				advance(potate, 1);
				if (potate == p.end())potate = p.begin();
			}
			auto foo = p.erase(potate);
			potate = prev(foo == p.begin() ? p.end() : foo);
		}
		cout << *potate + 1 << endl;
	}
}


Measured memory_bytes: 3092
#include<stdio.h>
int main()
{
  long a, b ;
  scanf("%ld%ld",&a,&b) ;

  long x ;
  long i ;
  for( i = 1 ; i <= b ; i++){
    x = a*i ;
    if(x%b == 0){
      printf("%ld\n",x) ;
      break ;
    }
  }

  return 0 ;
}

Measured memory_bytes: 128
import collections
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
m = 1000000007

flag0 = 1
count = 0
#偶数だったら
if N %2 ==0:
    colA = collections.Counter(A)
    for key,val in colA.items():
        if key%2 != 1 or val != 2:
            flag0 = 0
            break
    for i in range(1,N,2):
        if i not in colA.keys():
            flag = 0
            break
        else:
            count +=1
#奇数だったら
else:
    A.append(0)
    colA = collections.Counter(A)
    for key,val in colA.items():
        if key%2 != 0 or val != 2:
            flag0 = 0
            break
    for i in range(0,N,2):
        if i not in colA.keys():
            flag = 0
            break
        else:
            count +=1
    count -=1


print(((2**count)%m)*flag0)
    


Measured memory_bytes: 20636
#include <iostream>
#include <algorithm>
#include <bitset>
using namespace std;
using ll = long long;
int MOD = 1e9 + 7;
int mod(int a, int b){return (a%b + b) % b;}
int pangkat(int num , int derajat){
    if (derajat == 1)
        return num;
    if (derajat == 0)
        return 1;
    int x = pangkat(num , derajat / 2);
    x = (ll)x * x % MOD;
    if (derajat & 1)
        x = (ll)x * num % MOD;
    return x;
}
int main(){
    cin.tie(0);
    int pl = 0 , mn = 0;
    int N;
    cin >> N;
    string s;
    cin >> s;
    bitset<200000> b(s);

    int cnt = b.count();
    MOD = cnt + 1;
    for (int i = 0 ; i < N ; i++){
        if (b[i])
            pl = (pl + pangkat(2 , i)) % MOD;
    }
    if (cnt  != 1){
        MOD = cnt - 1;
        for (int i = 0 ; i < N ; i++){
            if (b[i])
                mn = (mn + pangkat(2 , i)) % MOD;
        }
    }
    for (int i = N - 1 ; i >= 0 ; i--){
        if (!b[i]){//giliran plus
            MOD = cnt + 1;
            int now = (pl + pangkat(2 , i)) % MOD , ans = 1;
            while(now > 0)
                ++ans , now %= __builtin_popcount(now);
            cout << ans;
        }
        else{
            MOD = cnt - 1;
            if (MOD == 0)
                cout << "0\n";
            else{
                int now = mod(mn - pangkat(2 , i) , MOD) , ans = 1;
                while(now > 0)
                    ++ans , now %= __builtin_popcount(now);
                cout << ans;
            }
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3748
using System;

namespace ABC057_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = sss[0];
            var M = sss[1];
            var x = new int[N];
            var y = new int[N];
            var px = new int[M];
            var py = new int[M];
            var ans = new int[N];
            for (var i = 0; i < N; i++)
            {
                var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                x[i] = xy[0];
                y[i] = xy[1];
            }
            for (var i = 0; i < M; i++)
            {
                var point = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                px[i] = point[0];
                py[i] = point[1];
            }
            for (var i = 0; i < N; i++)
            {
                var min = 900000000;
                for (var j = M - 1; j >= 0; j--)
                {
                    var dist = Math.Abs(x[i] - px[j]) + Math.Abs(y[i] - py[j]);
                    if (dist <= min)
                    {
                        min = dist;
                        ans[i] = j + 1;
                    }
                }
            }
            foreach (var ch in ans)
            {
                Console.WriteLine(ch);
            }
        }
    }
}


Measured memory_bytes: 11092
// implement a bst with insert and print

import java.util.Scanner;

public class Main {
	public static class node<T>{
		public T data;
		public node<T> p;
		public node<T> l_c;
		public node<T> r_c;
		
		public node(T _data) {
			data = _data;
			l_c = null;
			r_c = null;
			p = null;
		}
		
	}
	
	public static class bst<T extends Comparable<T>>{
		public node<T> root;
		
		public bst() {
			root = null;
		}
		//try to not use recursion in java if you want to modify some pointer data, since the pointer itself cannot be passed by reference
		
		public void insert(T key) {
			if(root == null) {
				root = new node<T>(key);
				return;
			}
			
			//otherwise we can make sure that current is not null
			node<T> p = null;
			node<T> current = root;
			while(current != null) {
				p = current;
				if(key.compareTo(current.data) <= 0) {
					current = current.l_c;
				}else {
					current = current.r_c;
				}
			}
			
			//which means the root itself is null
			if(key.compareTo(p.data) <= 0) {
				p.l_c = new node<T>(key);
				p.l_c.p = p;
			}else {
				p.r_c = new node<T>(key);
				p.r_c.p = p;
			}
			return;
		}
		
		
		//find whether a given key exists within the tree rooted by current
		private boolean _find(node<T> current, T key) {
			if(current == null) {
				return false;
			}
			
			if(current.data.equals(key)) {
				return true;
			}
			
			//otherwise, try to recursively search the key
			if(key.compareTo(current.data) < 0) {
				return _find(current.l_c, key);
			}
			return _find(current.r_c, key);
		}
		
		public boolean find(T key) {
			return _find(root, key);
		}
		
		
		//some helper function for display
		private void _inorder_print(node<T> current) {
			if(current == null) {
				return ;
			}
			
			_inorder_print(current.l_c);
			System.out.print(" "+current.data);
			_inorder_print(current.r_c);
			return;
			
		}
				
		public void inorder_print() {
			_inorder_print(root);
			System.out.println();
			return;
		}
		
		
		private void _preorder_print(node<T> current) {
			if(current == null) {
				return ;
			}
			
			System.out.print(" "+current.data);
			_preorder_print(current.l_c);
			_preorder_print(current.r_c);
			return;
		}
		
		
		public void preorder_print() {
			_preorder_print(root);
			System.out.println();
		}
	}
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int q_len = cin.nextInt();
		String cmd;
		int val;
		bst<Integer> bst = new bst<Integer>();
		while(q_len > 0) {
			cmd = cin.next();
			if(cmd.equals("insert")) {
				val = cin.nextInt();
				bst.insert(val);
			}else if(cmd.equals("print")) {
				bst.inorder_print();
				bst.preorder_print();
			}else if(cmd.equals("find")) {
				if(bst.find(cin.nextInt())) {
					System.out.println("yes");
				}else {
					System.out.println("no");
				}
			}
			
			q_len--;
		}
		cin.close();
		
	}
}

Measured memory_bytes: 300232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;


ll gcd(unsigned a, unsigned b) {

  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
    int n, k;
    cin>>n;
    
    ll a[202020],ans,ans2;
    ll r[2][202020]={};
    cin>>a[0]>>a[1];
    r[0][0]=a[0];r[1][0]=a[1];
    REP(i,2,n){
        cin>>a[i];
        r[i%2][i/2]=a[i]+r[i%2][i/2 -1];
    }
    if(n%2==0){
        ans=r[1][n/2 -1];
        rep(i,n/2){
            MAX(ans,r[0][i]+r[1][n/2 -1]-r[1][i]);
            
        }
        cout<<ans;
    }
    else{
        ans=r[1][n/2 -1];
        ans2=a[0];
        ans=max(ans,r[0][n/2]-a[0]);
        REP(i,1,n/2+1){
            ans=max(ans,r[0][n/2]-a[i*2]);
            ans=max(ans,r[1][i-1]+r[0][n/2]-r[0][i]);
            if(i>=2){
              ans2=max(ans2+a[i*2-1],r[0][i-2]+a[i*2-1]);
              ans=max(ans,ans2+r[1][n/2-1]-r[1][i -1]);
              ans=max(ans,ans2+r[0][n/2]-r[0][i]);
            }
        }
        
        
        cout<<ans;
    }
    EN;
}


Measured memory_bytes: 8364
N = int(input())
P = list(map(int, input().split()))
l = [float('inf')] * N
for i in range(1, N):
  l[i] = min(P[i - 1], l[i - 1])
cnt = 0
for i in range(N):
  if l[i] > P[i]:
    cnt += 1
print(cnt)

Measured memory_bytes: 24744
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;


int main() {
  string s;
  cin >> s;
  rep(i, s.size()){
    if(s[i]=='1') cout<<'9';
    else cout<<'1';
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll r;
    cin>>r;
    ll ans=3*r*r;
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  string s;
  cin >> s;
  REP(i, s.length()) {
    if (s[i] == 'C') {
      FOR(j, i, s.length()) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	string a, b, c; cin >> a >> b >> c;
	cout << 'A' << b[0] << 'C' << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

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

Measured memory_bytes: 256
import numpy as np

N, W = map(int, input().split())

value = np.zeros(W+1, dtype=np.int64) #value[w]は全重さwのときの持ち帰る品の価値の総和の最大値 

for i in range(N):
    w, v = map(int, input().split())
    value[w:] = np.maximum(value[w:], value[:-w]+v)

print(value[-1])

Measured memory_bytes: 15468
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define ll long long

int n, dp[10][10];
ll ans;

pii f(int x) {
  int a, b = x % 10;
  while (x) {
    a = x;
    x /= 10;
  }
  return {a, b};
}

int main() {
#ifdef LOCAL
  freopen("d.txt", "r", stdin);
  // freopen("main.txt","w",stdout);
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#endif
  cin >> n;
  memset(dp, 0, sizeof(dp));
  pii p;
  for (int i = 1; i <= n; i++) {
    p = f(i);
    dp[p.f][p.s]++;
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    p = f(i);
    ans += dp[p.s][p.f];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] cnt = new int[5];
            String s = "MARCH";

            for (int i = 0; i < n; i++) {
                String name = in.nextString();
                for (int j = 0; j < 5; j++) {
                    if (name.charAt(0) == s.charAt(j)) cnt[j]++;
                }
            }

            long ans = 0;
            for (int i = 0; i < 1 << 5; i++) {
                if (Integer.bitCount(i) == 3) {
                    long tmp = 1;
                    for (int j = 0; j < 5; j++) {
                        if ((i >> j & 1) == 1) {
                            tmp *= cnt[j];
                        }
                    }
                    ans += tmp;
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

using namespace std;

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

//#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; prll(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;



int main() {
	ll N;
	cin >> N;
	int N2 = 1 << N;
	vector<int> A(N2);

	REP(i, N2) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	
	vector<int> S;
	S.push_back(A.back());
	A.back() = -1;

	REP(i, N) {
		vector<int> P = S;
		sort(P.begin(), P.end());
		int Ai = (N2 - 1);
		while ((0 < P.size()) && (0 <= Ai)) {
			if (A[Ai] == -1) {
				Ai--;
				continue;
			}
			if (A[Ai] < P.back()) {
				S.push_back(A[Ai]);
				P.pop_back();
				A[Ai] = -1;
			}
			Ai--;
		}
		if (0 < P.size()) {
			print("No");
			return 0;
		}
	}
	print("Yes");
	return 0;
}


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

long long simplified_mahjong(vector<long long> v){

	long long count = 0;
	int remain = 0;

	for (long long i = 0; i < v.size(); ++i) {
		if(remain > 0 && v[i] > 0)
		{
			v[i]--;
			count++;
		}
		count += (v[i]/2);
		remain = (v[i]%2);
	}
	return count ;
}

int main (){
	vector<long long> v;
	long long n, x ;
	cin >> n ;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		v.push_back(x);
	}
	cout << simplified_mahjong(v);
	return 0 ;
}


Measured memory_bytes: 1908
import java.util.*;

public class Main { 
    public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      int o=0;
      if(a>9 || b>9){
        o=-1;
      }else{
      	o=a*b;
      }
      System.out.println(o);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    string s;
    cin>>s;
    vector<int> len;
    for(int i=0,prev=-1;i<s.size();++i){
        if(i==s.size()-1||s[i]==s[i+1]){
            len.push_back(i-prev);
            prev=i;
        }
    }
    int a[2]={0};
    for(int i=0;i<len.size();++i){a[i%2]+=len[i];}
    cout<<min(a[0],a[1])<<endl;
    return 0;
}


Measured memory_bytes: 1020
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[][] students = new int[n][n];
			int[][] x = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					students[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int columnMax = -1;
				for(int j = 0; j < n; j++){
					if(columnMax < students[j][i])
						columnMax = students[j][i];
				}
				for(int j = 0; j < n; j++){
					if(columnMax == students[j][i])
						x[j][i] |= 2;
				}
			}
			for(int i = 0; i < n; i++){
				int rowMin = Integer.MAX_VALUE;
				for(int j = 0; j < n; j++){
					if(rowMin > students[i][j])
						rowMin = students[i][j];
				}
				for(int j = 0; j < n; j++){
					if(rowMin == students[i][j])
						x[i][j] |= 1;
				}
			}
			
			Set<Integer> both = new HashSet<Integer>();
            for(int i = 0;i < n;i++)
                for(int j = 0;j < n;j++)
                    if(x[i][j] == 3)
                        both.add(students[i][j]);
			
            if(both.size() == 1){
            	StringBuilder sb = new StringBuilder();
                for(int v : both){
                    sb.append(v + " ");
                }
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }else{
            	System.out.println(0);
            }
		}
	}
}

Measured memory_bytes: 19540
s = input()
s_count = len(s)

is_r = True
r_count = 0
r_index = 0
l_count = 0
l_index = 0

ans = [0] * s_count

for i in range(s_count):
  current = s[i]
  if i == (s_count-1):
    next = ''
  else:
    next = s[i+1]
  if is_r:
    # Rを数えるターン
    if next == 'L':
      is_r = False
      r_index = i
      l_index = i+1
      ans[r_index] = 1
      ans[l_index] = 1
    else:
      r_count += 1
  else:
    # Lを数えるターン
    if next == 'R' or next == '':
      # R→Lの流れの最後
      if r_count > 0:
        ans[r_index] += r_count // 2
        ans[l_index] += r_count // 2
        if r_count % 2 == 1:
          ans[r_index] += 1
      
      if l_count > 0:
        ans[r_index] += l_count // 2
        ans[l_index] += l_count // 2
        if l_count % 2 == 1:
          ans[l_index] += 1
      
      total_count = r_count + l_count
      # print(total_count, r_count, l_count)
      if total_count % 2 == 1:
        tmp = ans[r_index]
        ans[r_index] = ans[l_index]
        ans[l_index] = tmp
        
      # リセット
      is_r = True
      r_count = 0
      r_index = 0
      l_count = 0
      l_index = 0
      
    else:
      l_count += 1


print(' '.join(map(str, ans)))

Measured memory_bytes: 54492
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long ans = 1;
    vector<long long> v(3, 0);
    for(int i = 0; i < N; i++){
        long long cnt = 0;
        int flag = -1;
        for(int j = 0; j < 3; j++){
            if(A[i] == v[j]) {
                cnt++;
                flag = j;
            }
        }
        if(cnt == 0){
            cout << 0 << endl;
            return 0;
        }
        ans = ans * cnt % MOD;
        v[flag]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4060
#include <stdio.h>

int c[30],cnt;

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	int  K[31],A[30][30];
	int i, j;

	for (i = 0; i < N; i++) {
		scanf("%d", &K[i]);
		for (j = 0; j < K[i]; j++) {
			scanf("%d", &A[i][j]);
			c[A[i][j]]++;
		}
	}
	for (i = 0; i < M; i++) {
		if (c[i+1] == N)cnt++;
	}
	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
   int n,i,result=0;
   scanf("%d",&n);
   int authNum[n];
   for (i=0;i<n;i++)
      scanf("%d",&authNum[i]);


   for (i=0;i<n;i++)
      if((authNum[i]%2==0) && (authNum[i]%3!=0) && (authNum[i]%5!=0)){
        printf("DENIED\n");return 0;
      }

   printf("APPROVED\n");
   return 0;
}

Measured memory_bytes: 128
n=gets.to_i
s=gets.split.map(&:to_i)
max=s[0];min=s[0];sum=0
0.upto(n-1) do |i|
    max=s[i] if s[i]>max
    min=s[i] if s[i]<min
    sum+=s[i]
end
puts "#{min} #{max} #{sum}"


Measured memory_bytes: 8888
/*
氏名 : 杉谷　裕貴,学籍番号 : 190441066
概要 : ミンコフスキー距離を求めるプログラム
*/
#include<math.h>
#include<stdlib.h>
#include<stdio.h>

int main(void)
{
	int n, i, j,k;/*変数の宣言*/
	int x[100], y[100];/*配列の宣言*/
	double d1, d2, d3,d4;/*実数の宣言*/
	int ab_value=0;

	scanf("%d\n", &n);/*整数の入力*/

	for (i = 0; i < n; i++)/*n回繰り返す*/
	{
		scanf("%d", &x[i]);/*ベクトルxの入力*/
	}

	for (j = 0; j < n; j++)/*n回繰り返す*/
	{
		scanf("%d", &y[j]);/*ベクトルyの入力*/
	}

	d1 = 0, d2 = 0, d3 = 0, d4 = -1;/*変数の初期化*/

	for (k = 0; k < n; k++)/*n回繰り返す*/
	{
		/*絶対値の計算*/

		d1 +=abs(x[k] - y[k]);/*マンハッタン距離の計算*/
	
		d2 += pow(fabs((double)x[k] - y[k]),2.0);/*ユークリッド距離の計算*/
	
		d3 += pow(fabs((double)x[k] - y[k]), 3.0);/*pが3の時の距離の計算*/
	
		if (d4 < abs(x[k]-y[k]))
		{
			d4 = abs(x[k] - y[k]);/*チェビシェフ距離の計算*/
		}
	}

	d2 = pow(d2, 1.0 / 2.0), d3 = pow(d3, 1.0 / 3.0);/*d2とd3計算*/

	printf("%f\n%f\n%f\n%f\n", d1, d2, d3, d4);/*各距離の表示*/

	return 0;
}


Measured memory_bytes: 2136
num = int(input())
num_array = input().split(" ")

for i in range(num):
    num_array[i] = int(num_array[i])


def put_array():
    for i in range(num):
        print(num_array[i], end="")
        if i != num-1:
            print(" ", end="")
        else:
            print("")

def insertionSort(A, N):
    for i in range(1, N):
        put_array()
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v


if __name__ == "__main__":

    insertionSort(num_array, num)

    put_array()


Measured memory_bytes: 6320
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define mod2 998244353
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
} 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
} 
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s; cin>>s;
	reverse(s.begin(), s.end());
	ll carpan = 1;
	int cnt[2020] = {};
	ll ans = 0;
	int n = s.size();
	for(int i = 0; i < n; i++){
		s[i] -= '0';
	}
	ll sum = 0;
	cnt[0]++;
	for(int i = 0; i < n; i++){
		sum = (sum + carpan * s[i]) % 2019;
		ans += cnt[sum];
		cnt[sum]++;
		carpan = (carpan * 10) % 2019;
	}
	cout<<ans<<endl;
}

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

using namespace std;
#define ll long long
#define f first
#define s second

int main()
{
    ll n,tmp,tmp2;

    string s,s2;
    cin >> s;
    
    for (int i=0; i<s.size()-1; i++)
    {
        if (s[i]==s[i+1]) return cout << i+1 << " " << i+2 << "\n" , 0;
    }

    for (int i=0; i<s.size()-2; i++)
    {
        if (s[i]==s[i+2]) return cout << i+1  << " " << i+3 << "\n" , 0;
    }
    cout << "-1 -1\n";

    return 0;
}


Measured memory_bytes: 512
{-# LANGUAGE BangPatterns #-}
import Data.List
import Control.Applicative

listsumcut :: [Int]->[Int]->[Int]
listsumcut [x] accum =accum
listsumcut !(x:xs) !(!a:(!accum)) = listsumcut xs $ (a+2*x):a:accum

solver (x:y:[]) = abs (x-y)
solver (x:xs) = minimum $ map abs $ listsumcut xs [x-(sum xs)]


main :: IO ()
main = do
    -- スペース区切り整数の入力
    getLine
    list <- map read . words <$> getLine
    -- 出力
    putStrLn $ show $ solver list



Measured memory_bytes: 109948
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if (n&1){
		int m=n*(n-1)/2-n/2;
		printf("%d\n",m);
		for (int i=1;i<=n;i++)
			for (int j=i+1;j<=n;j++)
				if (i+j!=n)printf("%d %d\n",i,j);
	}
	else {
		int m=n*(n-1)/2-n/2;
		printf("%d\n",m);
		for (int i=1;i<=n;i++)
			for (int j=i+1;j<=n;j++)
				if (i+j!=n+1)printf("%d %d\n",i,j);
	}
}


Measured memory_bytes: 256
# 写経
# にぶたん不要の解法
# https://atcoder.jp/contests/agc034/submissions/5768266
# generatorを作って
# 外でminする


def accumulate(a):
    """初項0"""
    su = 0
    yield su

    for x in a:
        su += x
        yield su


# class TestCaseReader:
#     def __init__(self):
#         self._gen = self.gen()
#
#     def gen(self):
#         import os
#         folder = r'XXX'
#         with open(os.path.join(folder, 'in.txt'), mode='r') as f:
#             for row in f:
#                 row = row.rstrip()
#                 yield row
#
#     def __call__(self):
#         return next(self._gen)


def solve_agc034c():
    from bisect import bisect_left
    from collections import namedtuple
    import sys
    input = sys.stdin.readline
    # input = TestCaseReader()

    Test = namedtuple('Test', 'Aoki_score lower_bound upper_bound')
    Test.Merit = lambda self, Takahashi_score: \
        self.lower_bound * Takahashi_score if Takahashi_score <= self.Aoki_score \
            else self.upper_bound * Takahashi_score - (self.upper_bound - self.lower_bound) * self.Aoki_score

    N, X = map(int, input().split())
    tests = []
    for _ in range(N):
        row = map(int, input().split())
        tests.append(Test(*row))
    tests.sort(key=lambda test: test.Merit(Takahashi_score=X), reverse=True)
    # 勝つ科目は重要度upper_bound,負ける科目は重要度lower_bound

    need = sum(test.lower_bound * test.Aoki_score for test in tests)

    *acc, = accumulate(test.Merit(Takahashi_score=X) for test in tests)

    bi = bisect_left(acc, need)  # bi問目まで完答でneed以上を達成(bi:1-indexed)=bi問解けばよい
    if bi == 0:
        print(0)  # 追加した
        return

    ge_need = acc[bi]  # need以上を達成するのに要した点数
    lt_need = acc[bi - 1]  # need未満の最大値を達成するのに要した点数

    def generate_candidates():
        INF = 10 ** 20
        for i, p in enumerate(tests, start=1):
            # p: partially_solved_test
            if i < bi:
                rest = need - (ge_need - p.Merit(Takahashi_score=X))
            else:
                rest = need - lt_need

            if rest <= p.Merit(Takahashi_score=p.Aoki_score):
                # 科目p単体の所要点数はAoki君以下でよく,lower_boundで計算
                add_ = (rest + p.lower_bound - 1) // p.lower_bound
            else:
                # 科目p単体の所要点数はAoki君を超える必要があり,upper_boundで計算
                add_ = p.Aoki_score
                add_ += (rest - p.Merit(Takahashi_score=p.Aoki_score) + p.upper_bound - 1) // p.upper_bound

            if add_ > X:
                yield INF
            else:
                ret = X * (bi - 1) + add_
                yield ret

    gen = generate_candidates()
    res = min(gen)
    print(res)
    return


if __name__ == '__main__':
    solve_agc034c()


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

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

	vector<int> dp(2000000, 0);
	for (int i = 1; i < 200; i++) {
		for (int j = 1; j < 200; j++) {
			for (int k = 1; k < 200; k++) {
				int tmp = i * i + j * j + k * k + i * j + j * k + k * i;
				dp[tmp]++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		cout << dp[i + 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 11108
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)s.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
const int maxn = 1e3;
int h,w ,sh,sw,th,tw;
char M[maxn][maxn];
int dist[maxn][maxn];
int dix[4] = {1,-1,0,0};
int diy[4] = {0,0,1,-1};
bool isValid (int a, int b) {
	return (a>=0 && a<h) && (b>=0 && b<w) && M[a][b]=='.';
}
void dfs () {
	F (i,0,h,1) {
		F (j,0,w,1) dist[i][j]=1e9;
	}
	deque <pin> D;
	dist [sw][sh] = 0;
	D.push_front(mkp(sw,sh));
	while (!D.empty ()) {
		pin q = D.front();
		D.pop_front();
		F (i,0,4,1) {
			if (isValid (q.fs+dix[i] , q.ss+diy[i]) && dist[q.fs+dix[i]][q.ss+diy[i]] > dist[q.fs][q.ss] ) {
				dist[q.fs+dix[i]][q.ss+diy[i]] = dist[q.fs][q.ss];
				D.push_front (mkp(q.fs+dix[i] , q.ss+diy[i]));
			}
		}

		F (i,-2,3,1) {
			F (j,-2,3,1) {
				if (isValid (q.fs+i , q.ss+j) && dist[q.fs+i][q.ss+j] > dist[q.fs][q.ss]+1) {
				dist[q.fs+i][q.ss+j] = dist[q.fs][q.ss]+1;
				D.pb(mkp(q.fs+i , q.ss+j));
			}

			}
		}
	}
} 
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
cin>>h>>w>>sw>>sh>>tw>>th;
--sw; --sh; --tw; --th;
// Taking matrix as input 
F (i,0,h,1) {
	F (j,0,w,1) cin>>M[i][j];
}
dfs ();
 if (dist[tw][th] == 1e9) cout<<-1;
 else cout<<dist[tw][th];
return 0;
}

Measured memory_bytes: 8596
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))

b = [x[1:] for x in a ]

c = []
for j in range(1,31):
    for k in range(n):
        if j in b[k]:
            c.append(j)

d = [x for x in set(c) if c.count(x) == n]

print(len(d))

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(250000)
input = sys.stdin.readline
import queue


def main():
    n, k = map(int, input().split())
    h = list(map(int,input().split()))

    cost = [sys.maxsize]*n
    cost[0] = 0
    for i in range(0,n):
        for j in range(1, k + 1):
            if (i+ j>= n):
                break
            abs_ = abs(h[i] - h[i+j])
            if cost[i+j] >cost[i] + abs_ :
                cost[i+j] = cost[i] + abs_
    print(cost[n-1])
main()


Measured memory_bytes: 89248
import java.util.*;
public class Main{
  public static void main(String[] args){
  	Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        String s = "";
        while(n > 0) {
            long mod = n%26;
            if(mod != 0) {
                char c = (char) (96 + mod);
                s = c + s;
                n = n/26;
            } else {
                s = 'z' + s;
                n = n/26;
                n--;
            }
        }
        System.out.println(s);

    
  }
}

Measured memory_bytes: 39708
import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * N
    used = [True] * N #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

N = int(input())

edge = [[] for i in range(N)]  # edge[i] : iから出る道の[重み,行先]の配列
for i in range(N-1):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])

Q, K = map(int, input().split())

zk = dijkstra_heap(K-1)
#print(zk)

for _ in range(Q):
    x, y = map(int, input().split())
    print(zk[x-1] + zk[y-1])


Measured memory_bytes: 55960
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = IINF;
    rep(i, (int)s.size() - t.size() + 1)
    {
        int cur = 0;
        rep(j, t.size())
        {
            if (s[i + j] != t[j])
            {
                cur++;
            }
        }
        chmin(ans, cur);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
a,b,c = gets.chomp.split.map(&:to_i)
if a>b then
  tmp = a
  a = b
  b = tmp
end
if a>c then
  tmp = a
  a = c
  c = tmp
end
if b>c then
  tmp = b
  b = c
  c = tmp
end
puts "#{a} #{b} #{c}"

Measured memory_bytes: 6096
S = list(input())
while len(S) > 0:
    if ''.join(S[-5:]) == 'dream' or ''.join(S[-5:]) == 'erase':
        S = S[:-5]
    elif ''.join(S[-6:]) == 'eraser':
        S = S[:-6]
    elif ''.join(S[-7:]) == 'dreamer':
        S = S[:-7]
    else:
        print('NO')
        quit()
print('YES')

Measured memory_bytes: 137088
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

typedef long long ll;

int N;
vector<int> A;
int sum;
ll trn;

void calcu(int p, char s) {
	if (p >= N)
		return;
	int x = A[p];
	if (s == '+') {
		if (sum + x <= 0)
			x = 1 - sum;
		sum += x;
		trn += abs(A[p] - x);
		calcu(++p, '-');
	}
	else {
		if (sum + x > 0)
			x = -1 - sum;
		sum += x;
		trn += abs(A[p] - x);
		calcu(++p, '+');
	}
}

int main(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	sum = (A[0] > 0) ? A[0] : 1;
	trn = (A[0] > 0) ? 0 : 1 - A[0];
	calcu(1, '-');
	ll a = trn;

	sum = (A[0] < 0) ? A[0] : -1;
	trn = (A[0] < 0) ? 0 : 1 + A[0];
	calcu(1, '+');
	ll b = trn;

	ll ans = (a < b) ? a : b;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back
 
using namespace std;
typedef long long ll;
ll N;
ll temp;
vector<ll> A;
int main(){
    cin >> N;
    rep(i,N) cin >> temp, A.pb(temp);
    sort(ALL(A));
    auto itr = lower_bound(ALL(A),0);
    int cnt = itr - A.begin();
    ll sum = 0;
    rep(i,N) sum += abs(A[i]);
    ll m = 1e18;
    rep(i,N) m = min(m,abs(A[i]));
    if(cnt % 2 == 1) sum -= 2*m;
    cout << sum << endl;
}

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

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n;++i)

typedef long long ll;

const int N = 302066;
const ll inf = 1e9;
int used[N];
set<int> s, t;
int a[N], n, m;
int u, v;
vector<int> g[N];

inline void dfs(int v) {
    used[v] = 1;
    s.insert(a[v]);
    t.insert(v);
    for(int to : g[v])
        if(!used[to])dfs(to);
}


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

    cin >> n >> m;
    fo(i, n) cin >> a[i];
    fo(i, m) {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int res = 0;
    fo(i, n) {

        if(!used[i]) {
            s.clear(); t.clear();
            dfs(i);
            for(int x : s) if(t.find(x) != t.end()) ++res;
        }

    }
    cout << res;
    return 0;
}

Measured memory_bytes: 22784
#include<bits/stdc++.h>
#define mp make_pair
#define endl "\n"
#define v vector
#define b begin()
#define e end()
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    float n,m;
    vector <int> arr;
    cin>>n>>m;
    int sum = 0,total = 0;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        arr.push_back(k);
        sum += k;
    }
    float val = sum/(4*m);

    //cout<<sum<<" "<<val;

    for(int i=0;i<n;i++){
        if(arr[i]>=val){
            total++;
        }
    }
    if(total>=m){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }


    return 0;

}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const ll MOD = 1e9+7;
ll dp[100010];
int main(){
    int n,m; cin >> n >> m;
    vector<bool> flag(n+1);
    rep(i,n+1) flag[i]=true;
    rep(i,m){
        int a; cin >> a;
        flag[a] = false;
    }
    dp[0] = 1;
    dp[1] = (flag[1]?1:0);
    rep(i,n-1){
        dp[i+2] += (flag[i+2]?((flag[i+1]?dp[i+1]:0) + (flag[i]?dp[i]:0)):0);
        dp[i+2]%=MOD;
    }
    cout << dp[n]%MOD << endl;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ('a' <= c && c <= 'z') {
                System.out.print((char) (c - 32));
            } else if ('A' <= c && c <= 'Z') {
                System.out.print((char) (c + 32));
            } else {
                System.out.print(c);
            }
        }
        System.out.println();
    }

}



Measured memory_bytes: 26892
n = int(input())
ss = []
for i in range(n):
    s, p = input().split()
    ss.append(s+"{:03}".format(200-int(p)))

sss = []
for s in ss:
    sss.append(s)
sss.sort()
for s in sss:
    print(ss.index(s)+1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int main()
{
    char a[105];
    int b;
    while(~scanf("%s",&a))
    {
        b=strlen(a);
        b-=2;
        printf("%c%d%c\n",a[0],b,a[b+1]);
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
p = [list(map(int, input().split())) + [i] for i in range(M)]
p.sort()
i = 0
for n in range(1, N + 1):
    count = 1
    while not(i >= M or p[i][0] != n):
        p[i] += [str(n).zfill(6) + str(count).zfill(6)]
        i += 1
        count += 1
p.sort(key=lambda x: x[2])
for a in p:
    print(a[3])

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

int main(){
    int n,b,f,r,v;
    cin >> n;
    int b1[3][10] = {{}};
    int b2[3][10] = {{}};
    int b3[3][10] = {{}};
    int b4[3][10] = {{}};
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        if(b==1){
            b1[f-1][r-1] = b1[f-1][r-1] + v;
        }
        else if(b==2){
            b2[f-1][r-1] = b2[f-1][r-1] + v;
        }
        else if(b==3){
            b3[f-1][r-1] = b3[f-1][r-1] + v;
        }
        else{
            b4[f-1][r-1] = b4[f-1][r-1] + v;
        }
    }
    
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            cout << " " << b1[j][k];
        }
        cout << endl;
    }
    
    for(int c=0;c<20;c++){
        cout << "#";
    }
    
    cout << endl;
    
    
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            cout << " " << b2[j][k];
        }
        cout << endl;
    }
    
    for(int c=0;c<20;c++){
        cout << "#";
    }
    
    cout << endl;
    
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            cout << " " << b3[j][k];
        }
        cout << endl;
    }
    
    for(int c=0;c<20;c++){
        cout << "#";
    }
    cout << endl;
    
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            cout << " " << b4[j][k];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 3e3;
int dp[MXN+5][MXN+5];
string A,B;


int rec(int ii, int jj){
    if(ii>=A.size() || jj>=B.size()) return 0;
    int &ret = dp[ii][jj];
    if(ret!=-1) return ret;
    if(A[ii]==B[jj]) return ret = rec(ii+1,jj+1) + 1;
    return ret = max ( rec(ii+1,jj) , rec(ii,jj+1) );
}

void watch(){
    for(int i=0; i<A.size(); i++){
        for(int j=0; j<B.size(); j++){
            cout<<setw(2)<<dp[i][j];
        }cout<<"\n";
    }cout<<"\n";
}

void solve(){

    memset(dp,-1,sizeof(dp));
    cin>>A>>B;
    int lcs_len = rec(0,0);
    int i=0,j=0;
    while(lcs_len){
        if(dp[i][j]==dp[i][j+1]) j++;
        else if(dp[i][j]==dp[i+1][j]) i++;
        else{
            cout<<B[j];
            i++,j++;
            lcs_len--;
        }
    }cout<<"\n";


}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
    solve();
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, p, min_p = 1e9, ans = 0;
	cin >> n;

	for(int i = 0; i < n; ++i)
	{
		cin >> p;
		if (p < min_p)
		{
			++ans;
		}
		min_p = min(min_p, p);
	}

	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256