akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = ReadLine().Split(' ').ToArray();
            string S = tmp[0];
            string T = tmp[1];
            WriteLine(T + S);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
using namespace std;

long long s,m=1e9,p,a;

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a<0) p++;
		m = min(m,abs(a));
		s += abs(a);
	}
	//cout<<p<<" "<<s<<endl;
	if(p%2==0) cout<<s;
	else cout<<s-2*m;
 	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[210000];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  sort(A,A+n);
  for(int i=0;i<n-1;i++){
    if(A[i]==A[i+1]){
      cout<<"NO\n";
      return 0;
    }
  }
  cout<<"YES\n";
  return 0;
}


Measured memory_bytes: 1024
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, K;

signed main(){
    cin >> N >> K;
    if(K == 0){
        cout << (ll)N*N << endl;
        return 0;
    }
    ll ans = 0;
    for(int b=K+1; b<=N; b++){
        ll tmp = (N)/b;
        ans += tmp * (b-K);
        ll tmp2 = N%b;
        if(tmp2 >= K) ans += tmp2-K+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
var
  f:array[0..3] of longint;
  i,j:longint;
begin
  read(f[1],f[2],f[3]);
  for i:=1 to 2 do
    for j:=i+1 to 3 do
      if f[i]<f[j] then begin f[0]:=f[i];f[i]:=f[j];f[j]:=f[0];end;
  if f[2]-f[1]=f[3]-f[2] then write('YES') else write('NO');
end.

Measured memory_bytes: 128
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
flag = True
cnt = 0
while(flag):
    for i in range(N):
        if A_list[i]%2!=0:
            flag=False
            break
        A_list[i]/=2
    cnt+=1
print(cnt-1)

Measured memory_bytes: 12484
n = int(input())
s = list(map(int, list(input())))
idx = [[] for _ in range(10)]
for i, v in enumerate(s):
    idx[v].append(i)

ans = 0
for i in range(1000):
    c = 0
    p = -1
    chk = True
    while c < 3 and chk:
        chk = False
        for j in idx[i // 100]:
            if j > p:
                c += 1
                p = j
                chk = True
                i = i % 100 * 10
                break
    if c == 3:
        ans += 1
print(ans)

Measured memory_bytes: 4496
def main():
    n, m, *a = map(int, open(0).read().split())
    t = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    a.sort(reverse=True)
    b = [t[i] for i in a]
    dp = [-float('Inf')] * (n + 10)
    dp[0] = 0
    for i in range(2, n + 1):
        dp[i] = max(dp[i - j] + 1 for j in b)

    nums = []
    for i in range(dp[n], 0, -1):
        for x in a:
            if dp[n - t[x]] == i - 1:
                nums.append(x)
                n -= t[x]
                break

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const int mod=1e9+7;
ll cum[N]; 

ll add(ll a,ll b){ 
    return ((a%mod)+(b%mod))%mod;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,k,ans=0,tot;
    cin>>n>>k;
    for(ll i=1;i<=n+1;i++){ 
       cum[i]=cum[i-1]+(i-1);
    }
    tot=n+1;
    for(ll i=k;i<=n+1;i++){ 
       ll r=cum[n+1]-cum[tot-i];
       ll l=cum[i];
       //cout<<l<<" "<<r<<endl; 
       //cout<<cum[tot]<<" "<<cum[tot-i]<<'\n';
       ans=add(ans,r-l+1);
       //cout<<ans<<'\n';
   }
   cout<<ans<<'\n';
 
    

    return 0;
}


Measured memory_bytes: 5196
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e9;



signed main(){
	int N;
	cin >> N;
	vector<int>cnt(N + 1);
	REP(i,N - 1){
		int t;
		cin >> t;
		cnt[t - 1]++;
	}
	REP(i,N)out(cnt[i]);
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[110];
    gets(a);
    int len=strlen(a),t=0;
    for(int i=0;i<len;i++)
	{
		if(a[i]=='C'&&t==0)t=1;
		if(a[i]=='F'&&t==1)t=2;
	}
	if(t==2)cout<<"Yes";
	else cout<<"No"; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c=0,d;
  cin>>a>>b;
  d=b+a-1;
  rep(i,a)c+=b+i;
  if(b<0){
    if(d>=0){
      cout<<c;
    }
    else cout<<c-d;
  }
  else if(b==0)cout<<c;
   else cout<<c-b;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	string s;
	cin >> s;
	deque<char> d;
	for (auto p : s) d.push_back(p);
	int n = s.size(), ans = 0;
	while (true) {
		if (n <= 1) break;
		if (d.front() == d.back()) {
			d.pop_front();
			d.pop_back();
			n -= 2;
		} else if (d.front() == 'x') {
			ans++;
			d.pop_front();
			n--;
		} else if (d.back() == 'x') {
			ans++;
			d.pop_back();
			n--;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
# include<bits/stdc++.h>
using namespace std;
int n,a[200009];
vector<pair<int,int> > A;
bool look(int d)
{
	A.clear();
	A.push_back(std::make_pair(0, 0));
	for (int i = 1; i <= n; ++i)
		if (a[i] <= a[i - 1])
		{
			while (A.back().first > a[i]) A.pop_back();
			for (int j = a[i]; ; --j)
			{
				if (j < 1) return false;
				int t = 1;
				if (A.back().first == j) t = 1 + A.back().second, A.pop_back();
				if (t < d) {A.push_back(make_pair(j, t));break;}
			}
		}
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	  scanf("%d",&a[i]);
	int l=1,r=n,ans=1;
	while(l<=r)
	{
		int mid(l+r>>1);
		if(look(mid)) ans=mid,r=mid-1;
		else l = mid+1;
	}
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from collections import defaultdict, Counter
from bisect import *

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
lb, rb = 1, 10**9+1
while lb+1 < rb:
    m = (lb+rb)//2
    x = min(X, A-bisect_left(p, m))
    y = min(Y, B-bisect_left(q, m))
    z = C-bisect_left(r, m)
    if z < (X-x)+(Y-y):
        rb = m
    else:
        lb = m
ans = 0
flg = 0
for i in range(A):
    if p[A-i-1] >= lb and i < X:
        ans += p[A-i-1]
    else:
        pb = i
        flg = 1
        break
if not flg:
    pb = X
flg = 0
for i in range(B):
    if q[B-i-1] >= lb and i < Y:
        ans += q[B-i-1]
    else:
        qb = i
        flg = 1
        break
if not flg:
    qb = Y
ans += sum(r[C-X-Y+pb+qb:])
print(ans)



Measured memory_bytes: 92516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

/*
4/N = 1/h + 1/n + 1/w
4/N = hn+nw+wh/hnw
4hnw = N(hn+nw+wh)
4hnw = Nhn+wN(n+h)
0 = Nhn+w(Nn+Nh-4hn)
w = Nhn/(4hn-Nn-Nh)
5
*/

int main(){
  ll N; cin >> N;
  for(ll h=1;h<=3500;h++){
    for(ll n=1;n<=3500;n++){
      ll a = (N*h*n);
      ll b = (4*h*n-N*n-N*h);
      if(a>0 && b>0 && a%b ==0){
        cout << h << " " << n << " " << a/b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

b = sorted(a)[::-1]
if N == 1:
    print(a[0])
elif N == 2:
    print(a[0])
elif N > 2 and N % 2 == 0:
    print(b[0] + sum(b[1:N // 2]) * 2)
elif N > 2 and N % 2 == 1:
    print(b[0] + sum(b[1:(N - 1) // 2]) * 2 + b[(N - 1) // 2])


Measured memory_bytes: 31432
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt(), Y=sc.nextInt(), S=0;
    Boolean b = false;
    for(int i=0; i<=X; i++) {
      S=i*2 + (X-i) * 4; 
      if(S==Y) {
        b = true;
        break;
      }
	}
    if(b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35772
#include "bits/stdc++.h"

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using ll = long long;

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

  int n, k, c;
  string s;
#if 1
  cin >> n >> k >> c >> s;
#else
  // Generate test case
  n = 10;
  k = 10;
  c = 2;
  for (int i = 0; i < n; i++) {
    s += (rand() % 2 == 0) ? 'o' : 'x';
  }
#endif

  vector<int> workdays(k);
  int wdPos = 0;

  stack<int> results;

  // workdaysを全部左に配置
  {
    for (int i = 0, day = 0; i < k; i++) {
      if (day >= n) return 0;
      while (s[day] == 'x') {
        day++;
        if (day >= n) return 0;
      }
      // この日が一番はやい出勤
      workdays[i] = day;
      day += c + 1;
    }
  }

  // workdaysを右から逆順にループ
  int day = n - 1;
  for (int i = k - 1; i >= 0; i--) {
    // なるべく右にできる場所を探す
    while (s[day] == 'x') {
      day--;
    }
    // この日が一番おそい出勤
    // 一番はやい出勤とイコールなら、この日は不動 = result列に追加
    if (day == workdays[i]) {
      results.push(day);
    }
    day -= c + 1;
  }

  while (results.size() > 0) {
    cout << (results.top() + 1) << '\n';
    results.pop();
  }
}


Measured memory_bytes: 3184
package main

import (
  "fmt"
)

func check_fact(i int, j int) uint{ //i*2**k がjを初めて超えるkを求める
  var k uint = 0
  // fmt.Println(i,j)
  for {
    // fmt.Println(k)
    if i*(2<<k) >= j{
      // fmt.Println(i*(2<<k),j)
      // fmt.Println(k)
      return k+1
    }
    k++

  }
}

func main(){
  var N, K int
  fmt.Scan(&N, &K)

  // fmt.Println(check_fact(1,17))
  var result float64
  if N < K{
    for i:=1; i<=N; i++{
      k := check_fact(i, K)
      // fmt.Println(i,k)
      // fmt.Println(1/float64((2<<(k-1))*N))
      result += 1/float64((2<<(k-1))*N)
    }
    fmt.Println(result)
  }else{
    for i:=1; i<K; i++{
      k := check_fact(i, K)
      // fmt.Println(i,k)
      // fmt.Println(1/float64((2<<(k-1))*N))
      result += 1/float64((2<<(k-1))*N)
    }
    result += float64(N-K+1)/float64(N)
    fmt.Println(result)
  }
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main{
    static IntStream REPS(int v){return IntStream.range(0,v);}
    static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
    static IntStream INS(int n) {return REPS(n).map(i->getInt());}
    static Scanner s=new Scanner(System.in);
    static int getInt(){return Integer.parseInt(s.next());}
    public static void main(String[]$){
        int n=getInt(),cn=n;
        int rn=0;
        while(cn!=0) {
            rn*=10;
            rn+=cn%10;
            cn/=10;
        }
        System.out.println(rn==n?"Yes":"No");
    }
}

Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);

        List<Integer> list = new ArrayList<>(3);
        for (int i = 0; i < 3; i++) {
            list.add(scan.nextInt());
        }
        
        List<Integer> result = list.stream().sorted().collect(Collectors.toCollection(ArrayList::new));

        System.out.println(result.get(0) + result.get(1));

        scan.close();
    }
}

Measured memory_bytes: 28500
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

const double PI=3.14159265358979323846;
int main()
{
    double R;

    cin >> R;

    printf("%f\n", (2 * R * PI));
    
    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long i,j,cnt2=0,ans=0,a,b;
   cin>>a>>b;
   if(a==0)
   {
      ans=b*1;
      if(b==100)ans+=1;
   }
   else if(a==1)
   {
      ans=b*100;
      if(b==100)ans+=100;
   }
   else
   {
     ans=b*10000;
     if(b==100)ans+=10000;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
import math

N, H = map(int, input().split())
A, B = [], []

for _ in range(N):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)

B.sort()
B.reverse()
count = 0
Amax = max(A)

# 最後に振り続ける刀 amax より大きい投げパワーの刀を全部投げる
for i in range(N):
    if B[i] > Amax:
        H -= B[i]
        count += 1
    if H <= 0: # 倒し終わった
        print(count)
        exit()

# 残り
count += math.ceil(H / Amax)
print(count)

Measured memory_bytes: 62168
#!/usr/bin/perl
use Data::Dumper;
my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = sort {$a <=> $b} map {$_ - 0} split(/\s+/o,<STDIN>);

my $a1 = $a[$#a];
my $a2 = $a[0];
my $a1_2 = $a1 / 2;
if( $n>2 ){
  my $dist = abs($a2 - ($a1_2));
  for(my $i=0;$i<$n-1;$i++){
    my $cd = abs($a[$i] - ($a1_2));
    if( $cd<$dist ){
      $dist = $cd;
      $a2 = $a[$i];
    }
  }
}
print "$a1 $a2\n";

exit(0);


Measured memory_bytes: 21600
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n, m, i, j, t;
	vector<int> bibs;
	scanf("%d %d", &n, &m);

	for(i = 0;i < n;++i){
		scanf("%d", &t);
		bibs.push_back(t);
	}

	for(i = 0;i < m;++i){
		//?????????i?????????????????????
		for(j = 0;j < n-1;++j){
			if(bibs[j]%(i+1) > bibs[j+1]%(i+1)){
				t = bibs[j];
				bibs[j] = bibs[j+1];
				bibs[j+1] = t;
			}
		}
	}

	for(i = 0;i < n;++i) printf("%d\n", bibs[i]);

	return 0;
} 

Measured memory_bytes: 2804
#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)

using ll = long long;
#define INF 1e9

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(A+B-N, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
    $a;
    fscanf(STDIN, "%d", $n);
    for($i = 1; $i <= 3500; $i++){
        for($j = 1; $j <= 3500; $j++){
            $x = 4 * $i * $j - $n * $j - $n * $i;
            $y = $i * $j * $n;
            if($x > 0 && $y % $x == 0){
                echo "$i $j ", ($y / $x), "\n";
                exit;
            }
        }
    }
?>


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int k, a, b;
    cin >> k >> a >> b;

    int len = k * ((a+k-1)/k);
    //cout << len;
    if (len <= b) cout << "OK" << endl;
    else cout << "NG" << endl;

}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

/*class teleport{
public:
    ll n,k;
    vector<ll> A;
    vector<bool> flag;
    teleport(){
        cin>>n>>k;
        A.resize(n);
        flag.resize(n,false);
        REP(i,n) {
            cin >> A[i]; A[i]--;
        }
    }

    while(fl)
}

ll tel(ll now){
    if(flag[now] )
}*/

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll n,k;
    cin>>n>>k;
    vector<ll> A(n);
    REP(i,n) {
        cin >> A[i]; A[i]--;
    }
    vector<bool> flag(n,false);

    ll start = 0;
    ll itr = 0;
    while(flag[start] == false){
        flag[start] = true;
        start = A[start];
        itr++;
        if(itr == k){
            cout << start+1 << endl;
            return 0;
        }
    }
    vector<ll> loop;
    ll now = start;
    //ll rep = 0;
    do{
        loop.push_back(now);
        //rep++;
        now = A[now];
    }while(now != start);
    //cout << start << endl;
    //cout << itr << " " << loop.size() << endl;
    itr -= loop.size();
    k -= itr;

    ll amari = k % loop.size();
    cout << loop[amari]+1 << endl;
    return 0;
    
    
}

Measured memory_bytes: 5804
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if (A ^ 2 + B ^ 2 == C ^ 2) {
		printf("%d", A * B / 2);
	}else if (A ^ 2 + C ^ 2 == B ^ 2) {
		printf("%d", A * C / 2);
	}else {
		printf("%d", C * B / 2);
	}
	return 0;
}

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

int main(){
  string a,b;
  cin>>a>>b;
  int val = stoi(a+b);
  
  bool flag=false;
  for (int i=1;i<=val;i++) {
    if (val%i==0 && val/i==i) flag=true;
  }
  
  cout << (flag?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll n,m,ans;
	ans=1;
	cin >> n >> m;
	ll M = m;
	for(ll i=m/n;2<=i*i;i--)
	{
		if(m%i==0&&n<=m/i)
		{
			//cout<<m<<':'<<i<<endl;
			m/=i;
			ans=i;
			break;
		}
	}	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *      ABC 65 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-23 18:25:57
**/

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, M; cin >> N >> M;
    ll MOD = 1000000000 + 7;

    if (N == M){
        ll answer = 1;
        for (auto i = 1; i <= N; ++i) {
            answer *= i;
            answer %= MOD;
        }
        cout << (answer * answer * 2) % MOD << endl; 
    }
    else if (abs(N - M) == 1){
        ll answer1 = 1; ll answer2 = 1;
        for (auto i = 1; i <= N; ++i) {
            answer1 *= i;
            answer1 %= MOD;
        }
        for (auto i = 1; i <= M; ++i) {
            answer2 *= i;
            answer2 %= MOD;
        }
        cout << (answer1 * answer2) % MOD << endl;
    }
    else {
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> vc;
    while(n--) {
        string x;
        cin >> x;
        vc.push_back(x);
    }
    n = vc.size();

    map<string, int> mp;

    for (int i = 0; i < n; i++) {
        string str = vc[i];
        mp[str] = mp[str] + 1;
    }

    int max = 0;
    for( auto it = mp.begin(); it != mp.end(); ++it ) {
        auto key = it->first;
        auto value = it->second;
        if (value > max) {
            max = value;
        }
    }

    for( auto it = mp.begin(); it != mp.end(); ++it ) {
        auto key = it->first;
        auto value = it->second;
        if (value == max) {
            cout << key << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 23660
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H, W, i, j;
    
    while(1){
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        
        for (i=0;i<H;i++){
            
            if(i==0 || i%2==0){
                for(j=0;j<W;j++){
                    if(j==0 || j%2==0) cout<<"#";
                    else cout<<".";
                }
            } else {
                 for(j=0;j<W;j++){
                    if(j==0 || j%2==0) cout<<".";
                    else cout<<"#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
const ll inf = 1e15;
int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll dp[100005][2];
    dp[0][0] = 0;
    dp[0][1] = -inf;
    rep(i,N){
        dp[i+1][0] = max(dp[i][0] + A[i],dp[i][1] - A[i]);
        dp[i+1][1] = max(dp[i][0] - A[i],dp[i][1] + A[i]);
    }

    cout << dp[N][0] <<endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int solve(){
  int base=0,out=0,point=0;
  string key;
  while(out!=3){
    cin>>key;
    if(key=="HIT"){
      if(base&1<<2)point++;
      base<<=1;base++;
    }else if(key=="HOMERUN"){
      point++;
      for(int j=0;j<3;j++)if(base&1<<j)point++;
      base=0;
    }else if(key=="OUT")out++;
  }
  return point;
}
int main(){
  int a;
  cin>>a;
  for(int i=0;i<a;i++)cout<<solve()<<endl;
}

Measured memory_bytes: 1212
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;


/*
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x%y);
}
/*
ll lcm(ll x, ll y) {
ll g = gcd(x, y);
return x / g * y;
}
ll pw(int x, int n) {
ll y = 1;
ll p = x;
while (n != 0) {
if (n % 2) {
y = y*p%mod;
n = n - 1;
}
else {
p = p*p%mod;
n = n / 2;
}
}
return y;
}

ll modinv(ll x) {
return pw(x, mod - 2);
}*/

int x_1, x_2, y_1, y_2;

int main() {
	cin >> x_1 >> y_1 >> x_2 >> y_2;
	cout << x_2 - (y_2 - y_1) << sp << y_2 - (x_1 - x_2) << sp << x_1 - (y_2 - y_1) << sp << y_1 - (x_1 - x_2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;scanf("%d%d",&n,&m);
    vector<vector<int>> G(n,vector<int>()),lang(m,vector<int>());
    for(int i=0;i<n;i++){
        int k;scanf("%d",&k);
        for(int j=0;j<k;j++){
            int l;scanf("%d",&l);l--;
            lang[l].push_back(i);
        }
    }
    for(int i=0;i<m;i++){
        int s=lang[i].size();
        if(s<2)continue;
        for(int j=1;j<s;j++){
            G[lang[i][0]].push_back(lang[i][j]);
            G[lang[i][j]].push_back(lang[i][0]);
        }
    }
    vector<int> dist(n,1e9);
    dist[0]=0;
    queue<int> que;que.emplace(0);
    while(que.size()){
        int q=que.front();que.pop();
        for(auto nq:G[q]){
            if(dist[nq]>dist[q]+1){
                dist[nq]=dist[q]+1;
                que.emplace(nq);
            }
        }
    }
    bool check=0;
    for(int i=0;i<n;i++)if(dist[i]==1e9)check=1;
    if(check)printf("%s\n","NO");
    else printf("%s\n","YES");
    return 0;
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
const int maxn=1e6+100;
const double pi=4.0*atan(1.0);
int n,m,k,q;
int T;
string str;
int main()
{
    cin>>n;
    cin>>str;
    if(str.length()<=n)
        cout<<str<<endl;
    else
        cout<<str.substr(0,n)+"..."<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    if (s[1] == 'B')cout << "ARC\n";
    else cout << "ABC\n";
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int l;
    cin >> l;

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

    if (s + t > t + s) swap(s, t);

    int a = s.size(), b = t.size();
    int i1, j1;
    for (int i = 0; i <= l; i += a) {
        if ((l - i) % b == 0) {
            i1 = i / a;
            j1 = (l - i) / b;
        }
    }

    string r; r.reserve(l);
    for (int i = 0; i < i1; i++) {
        r += s;
    }
    for (int i = 0; i < j1; i++) {
        r += t;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1684
#include<stdio.h>
int main(void){
 int x, y;
 while(1){
 scanf("%d %d", &x, &y);
 if(x == 0 && y == 0)break;
 if(x > y){printf("%d %d\n", y, x);
 }
 else{printf("%d %d\n", x, y);
 }
 }
 return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  string S;
  cin >> S;
  int C;

  //SOLVE

  if (S=="SUN") {
    C = 7;
  }
  if (S=="MON") {
    C = 6;
  }  if (S=="TUE") {
    C = 5;
    }  if (S=="WED") {
      C = 4;
      }  if (S=="THU") {
        C = 3;
        }  if (S=="FRI") {
          C = 2;
          }if (S=="SAT") {
            C = 1;
            }

  //OUTPUT
  cout << C << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int keta(int n){
  int count = 0;
  for(int i = 0; i <= 11; i++){
    n /= 10;
    count++;
    if(n == 0) break;
  }
  return count;
}

int main(){
  int64_t N;
  int min1 = 10000;
  cin >> N;
  int min;
  for(int i = 1; i <= 100000; i++){
    if(N%i == 0){
      min = max(keta(i), keta(N/i));
      if(min1 > min){
        min1 = min;
      }
    }
  }
  cout << min1 << endl;
}

Measured memory_bytes: 256
// be name khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push
const ll maxn=3*1e5+5;
stack <ll> s,s1;
ll a[maxn],stt[maxn],ttt[maxn];
int main()
{
        ios::sync_with_stdio(false);ll n;cin >> n;for(ll i=1; i<=n; i++){cin >> a[i];if(!s.empty()){ll k=0;while(!s.empty() && s.top()>a[i]){ll XD;XD=s1.top();ttt[XD]=k+1;k+=stt[XD];s.pop();s1.pop();}stt[i]=k+1;s.push(a[i]);s1.push(i);}else{stt[i]=1;s.push(a[i]);s1.push(i);}}ll k=0;while(!s.empty()){ll XD;XD=s1.top();ttt[XD]=k+1;k+=stt[XD];s.pop();s1.pop();}ll ans=0;for(ll i=1; i<=n; i++){ans+=stt[i]*ttt[i]*a[i];}cout << ans;
}
// bikari


Measured memory_bytes: 8048
#import sys
#input = sys.stdin.readline
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    sa = sum(A)
    R = factors(sa)
    l = len(R)
    E = [0]*l
    ans = 0
    for r in R:
        cnt = 0
        E = list( map( lambda x:x%r, A))
        E.sort()
        s = sum(E)
        now = 0
        if s - E[-1] <= K:
            if ans < r:
                ans = r
            continue
        if s == 0:
            continue
        v = 0
        w = N-1
        cnt = 0
        while w-v != 0:
            if E[v] == 0:
                v += 1
                continue
            if E[w] == 0:
                w -= 1
                continue
            if E[v] + E[w] >= r:
                E[v] -= r - E[w]
                cnt += r - E[w]
                E[w] = 0
                w -= 1
            else:
                E[w] += E[v]
                cnt += E[v]
                E[v] = 0
                v += 1
        if cnt <= K:
            if r > ans:
                ans = r
    print(ans)
if __name__ == '__main__':
    main()


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

int main() {
    int n;
    cin >> n;
 
    priority_queue<double, vector<double>, greater<double>> pq;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        pq.push(a);
    }
    double value;
    while(!pq.empty()){
        double x,y;
        value = 0;
        x = pq.top();
        pq.pop();
        y = pq.top();
        pq.pop();
        value = (x + y) / 2;
        if(!pq.empty()){
            pq.push(value);
        }
    }
    cout << value << endl;
}
    


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
	int H, W;
	cin >> H >> W;

	string s;

	for (int i = 0; i < H; ++i)
	{
		string temp;
		cin >> temp;

		s += temp + '\n';
		s += temp + '\n';
	}

	cout << s << endl;


	return 0;
}

Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    string s; cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3608
use proconio::input;

fn main() {
	input!(s: [String; 3]);

	let name = ['A', 'B', 'C'];
	//let mut s = s;
	let mut turn: usize = 0;
	let mut v = vec![vec![]; 3];
	for i in 0..3 {
		v[i] = s[i].chars().collect();
	}
	loop {
		if v[turn].len() == 0 {
			println!("{}", name[turn]);
			return;
		}
		let tmp = v[turn][0] as usize - 'a' as usize; 
		v[turn].remove(0);
		turn = tmp;
	}
}



Measured memory_bytes: 2136
fun main(args: Array<String>) {
    val (x1, x2, x3 , x4, x5) = readLine()!!.split(' ').map { it.toInt() }
    println(when{
        x1 == 0 -> 1
        x2 == 0 -> 2
        x3 == 0 -> 3
        x4 == 0 -> 4
        x5 == 0 -> 5
        else -> 0
    }
    )
}


Measured memory_bytes: 36236
#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>;

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

	string	s;
	cin >> s;
	bitset<200> bs;
	rep(i, s.size())
		bs.set(s.at(i));
	for (char c = 'a'; c <= 'z'; c++)
	{
		if (!bs.test(c))
		{
			cout << c << endl;
			return (0);
		}
	}
	cout << "None" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main (void)
{
    char str[100];
    int cnt, i, ans;

    scanf("%s", str);

    for (cnt = 0; str[cnt] != '\0'; cnt++);

    ans = 0;

    for (i = 0; i < (cnt / 2); i++) {
        if (str[i] == str[cnt - 1 - i]) continue;

        ans++;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD (long long)(1e8 + 7)
using namespace std;

string s;

long long solve();
long long calc(long long len, long long msize);

int main() {
  while(1) {
    cin >> s;
    if(s == "#") break;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long ans = 1, ssize = s.size();
  for(int i = 0; i < ssize; ++i) {
    char now = s[i];
    long long cnt = 0, nowsize = 3;
    if(now != '0' && now != '8') nowsize += 2;
    while(i < ssize && s[i] == now) ++i, ++cnt;
    (ans *= calc(cnt, nowsize)) %= MOD;
    --i;
  }
  return ans;
}

long long calc(long long len, long long msize) {
  long long ans = 0;
  vector<long long> dp;
  dp.assign(msize, 0);
  dp[len % msize] = 1;
  for(int i = 0; i < len; ++i) {
    long long sum = 0;
    for(int j = 0; j < msize; ++j) (sum += dp[j]) %= MOD;
    if((len - 1 - i) % msize == 0) (ans += sum) %= MOD;
    dp[(len - 1 - i) % msize] = sum;
  }
  return ans;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const ll p=1000000007;
ll m[51];
ll o[51];
ll solve(ll n,ll k){
  if(k==0)return 0;
  if(k==m[n]||(k==m[n]-1&&n!=0))return o[n];
  if(k==1&&n==0)return 1;
  if(k==1)return 0;
  if(k*2+1==m[n])return o[n-1];
  if(k*2-1==m[n])return 1+o[n-1];
  if(k*2+1<m[n])return solve(n-1,k-1);
  return o[n-1]+1+solve(n-1,k-2-m[n-1]);
}
int main(){
  ll n,k;
  cin >> n >> k;
  o[0]=1;
  rep(i,50)o[i+1]=o[i]*2+1;
  m[0]=1;
  rep(i,50)m[i+1]=m[i]*2+3;
  cout << solve(n,k) << endl;
}


Measured memory_bytes: 256
S = gets.chomp
n = S.length
a = 0
b = 0

for i in 0..n do
  if S[i] == "A" || S[i] == "T" || S[i] == "G" || S[i] == "C"
    a += 1
  else
    if a > b
      b = a
      a = 0
    end
  end
end
puts b

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){

	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

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

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(abs(x - a) < abs(x - b))	puts("A");
	else puts("B");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define INF 1 << 30
#define MIN_INF (-1)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;


int main(){
    int N;
    cin >> N;
    vector<ll> as(N);
    rep(i, N){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    ll ans = 0;
    for(int i = 0; i < N - 1; i += 2){
        if(as[i] + as[i + 1] < 0){
            as[i] *= -1;
            as[i + 1] *= -1;
        }
    }
    rep(i, N){
        ans += as[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int gem[100], cost[100];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) 
		cin >> gem[i];
	for (int i = 0; i < n; ++i)
		cin >> cost[i];
	int ans = 0;
	for (int i = 0; i < n; ++i)
		if (gem[i] - cost[i] > 0)
			ans += gem[i] - cost[i];
	cout << ans << '\n';
	return 0;
}

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

int64_t LucasNumber(int N) {
  vector<int64_t> l(N+1);
  l.at(0) = 2;
  l.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    l.at(i) = l.at(i-2) + l.at(i-1);
  }
  
  return l.at(N);
}

int main() {
  int N;
  cin >> N;
  
  cout << LucasNumber(N) << endl; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String str = in.nextLine();
    in.close();
    StringBuilder ans = new StringBuilder();
    ans.append(str.charAt(0));
    ans.append(str.length() - 2);
    ans.append(str.charAt(str.length() - 1));
    System.out.println(ans);
  }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N, M; cin >> N >> M;

	
	
	LL ans = abs(N-2)*abs(M-2);
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    while (true) {
      int n = cin(), k = cin();
      if (n + k == 0) return;
      int[] a = new int[n];
      for (int i = 0; i < n; i++) a[i] = cin();

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

      int max = int.MinValue;
      for (int i = 0; i < n-k+1; i++) {
        max = (max < sum[i+k] - sum[i]) ? sum[i+k] - sum[i] : max;
      }

      Console.WriteLine(max);
    }
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}



Measured memory_bytes: 18720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

ll modP(ll x, ll y, ll MOD)
{
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
void solve()
{
    ll ans = 0;
 
 
ll x; 
cin>>x; 
ll p=600; 
ans=8; 
while(x>=p) 
{
    p+=200; 
    ans--;
}

    cout << ans << "\n";
}int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t ;
    t = 1;
 
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}





Measured memory_bytes: 3648
grid = 3.times.map { gets.split.map(&:to_i) }
N = gets.to_i
B = N.times.map { gets.to_i }
board = Array.new(3) { Array.new(3, false) }
B.each do |b|
  3.times do |i|
    3.times do |j|
      if grid[i][j] == b
        board[i][j] = true
      end
    end
  end
end

if board.any? { |row| row.all?(&:itself) }
  puts 'Yes'
  exit 0
end

is_ok = (board[0][0] && board[1][0] && board[2][0]) ||
  (board[0][1] && board[1][1] && board[2][1]) ||
  (board[0][2] && board[1][2] && board[2][2])
if is_ok
  puts 'Yes'
  exit 0
end

if board[0][0] && board[1][1] && board[2][2]
  puts 'Yes'
  exit 0
end

if board[0][2] && board[1][1] && board[2][0]
  puts 'Yes'
  exit 0
end

puts 'No'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,c=0,t,a,b,s;
    cin>>a>>b>>c;
    n = c-b;
    if(c-b <= 0)
    {
        cout<<"delicious\n";
    }
    else if(n <= a)
    {
        cout<<"safe\n";
    }
    else
    {
        cout<<"dangerous\n";
    }
}


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

int main() {
    int n;
    cin >> n;
    
    for(int i=1; i<=n; i++) {
        if(i%3 == 0) {
            cout << " " << i;
            continue;
        }
        
        int x = i;
        
        while(x != 0) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3076