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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int N;
    cin >> N;
    vector<LL> A(N);
    REP0 (i, N)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), [](LL a, LL b) { return a > b; });
    vector<pair<LL, LL>> S;
    for (int i = 1; i < N - 1; i++)
    {
        if (A[i] >= 0)
        {
            S.push_back(make_pair(A[N - 1], A[i]));
            A[N - 1] -= A[i];
        }
        else
        {
            S.push_back(make_pair(A[0], A[i]));
            A[0] -= A[i];
        }
    }
    S.push_back(make_pair(A[0], A[N - 1]));
    A[0] -= A[N - 1];
    std::cout << A[0] << endl;
    for (auto p : S)
    {
        std::cout << p.first << " " << p.second << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
int main(){
    
  int N, K;
  int x;
  int ans;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
      cin >> x;
      if ((x >= K && x*2 < (x - K)*2)
        || (x < K && (x*2*(-1)) > (x - K)*2)){
          ans += x*2;
      }
      else if (x >= K){
          ans += (x - K)*2;
      }
      else{
          ans -= (x - K)*2;
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
// By Debajit Chakraborty
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define rev(i,j,x) for(int i=j;i>=x;i--)
#define mem(x,val) memset(x,val,sizeof(x))
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
 
const int mod=1e9+7;
const int N=2e5+10;
const int INF=1e8;


int n,k,lo,hi,mid,ans,a[N];

int chk(int x){
    int cnt=0;
    rep(i,1,n){
        cnt+=(a[i]-1)/x;
    }
    return (cnt<=k);
}

void solve(){
    cin>>n>>k;
    hi=0;
    int sum=0;
    rep(i,1,n){
        cin>>a[i];
        hi=max(hi,a[i]);
        sum+=2*a[i];
    }
    
    lo=1;
    ans=hi;
    while(lo<hi){
        mid=(lo+hi)/2;
        if(chk(mid)){
            hi=mid;
            if(ans==hi)
            	break;
            ans=hi;
        }
        else{
            lo=mid+1;
        }
    }
    if(ans!=1 and chk(ans-1))
    	ans--;
    cout<<ans<<endl;
}


int32_t main()
{
    SPEED;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        //cout<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
}

Measured memory_bytes: 5180
var
  n,m,i,j,k,l,t:longint;
  a:array[0..60,0..60]of char;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      for j:=1 to m do
        read(a[i,j]);
      readln;
    end;
  for i:=1 to n do
    begin
      for j:=1 to m do
        if a[i,j]='#' then write(a[i,j])
                      else
                        begin
                          t:=0;
                          for k:=i-1 to i+1 do
                            for l:=j-1 to j+1 do
                              if a[k,l]='#' then inc(t);
                          write(t);
                        end;
      writeln;
    end;
end.

Measured memory_bytes: 128
#include <iostream>
#define ll long long
using namespace std;

ll yakusu(ll a,ll b){
	ll y=a;
	while(y>0){
		if(a%y==0){
			if(b%y==0){
				return y;
			}
		}
		y--;
	}
	return 1;
}

int main() {
    ll K;
    cin >> K;
	ll sum=0;
	for(ll a=1;a<K+1;a++){
		for(ll b=1;b<K+1;b++){
			ll tmp = yakusu(a,b);
			for(ll c=1;c<K+1;c++){
				sum += yakusu(tmp,c);
			}
		}
	}
    cout<< sum <<endl;

    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

using ll = long long;
const long long MOD = 1e9+7;

using Int = long long;
struct ModInt {
    static Int mod;
    Int val;
    ModInt(Int v = 0) : val(v % mod) {}
    ModInt operator-() const { return ModInt(val ? mod - val : val); }
    ModInt &operator+=(ModInt a) {
        if ((val += a.val) >= mod) val -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt a) {
        if ((val -= a.val) < 0) val += mod;
        return *this;
    }
    ModInt &operator*=(ModInt a) {
        val = (__uint128_t(val) * a.val) % mod;
        return *this;
    }
    ModInt &operator/=(ModInt a) {
        Int u = 1, v = a.val, s = 0, t = mod;
        while (v) {
            Int q = t / v;
            swap(s -= u * q, u);
            swap(t -= v * q, v);
        }
        a.val = (s < 0 ? s + mod : s);
        val /= t;
        return (*this) *= a;
    }
    ModInt inv() const { return ModInt(1) /= (*this); }
    bool operator<(ModInt x) const { return val < x.val; }
};
Int ModInt::mod = 1e9 + 7;

ostream &operator<<(ostream &os, ModInt a) {
    os << a.val;
    return os;
}
ModInt operator+(ModInt a, ModInt b) { return a += b; }
ModInt operator-(ModInt a, ModInt b) { return a -= b; }
ModInt operator*(ModInt a, ModInt b) { return a *= b; }
ModInt operator/(ModInt a, ModInt b) { return a /= b; }
ModInt pow(ModInt a, Int e) {
    ModInt x(1);
    for (; e > 0; e /= 2) {
        if (e % 2 == 1) x *= a;
        a *= a;
    }
    return x;
}

map<int, int> prime_number_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() { 
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    
    map<int, int> common_primes;
    for (int i = 0; i < n; i++) {
        auto ps = prime_number_factor(a.at(i));
        if (i == 0) for (auto p: ps) common_primes[p.first] = p.second;
        else for (auto p: ps) chmax(common_primes[p.first], p.second);
    }

    ModInt l = 1;
    for (auto p: common_primes) {
        l *= pow(ModInt(p.first), p.second);
    }
    
    ModInt res = 0;
    for (int i = 0; i < n; i++) {
        res += l / ModInt(a.at(i));
    }
    cout << res << endl;
}   

Measured memory_bytes: 768
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for ( v = 0; v < n; v++ ){
    if ( M[u][v] == 0 ) continue;
    if ( color[v] == WHITE ){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for ( u = 0;u < n; u++ ) color[u]= WHITE;
  tt = 0;
  for ( u = 0; u < n; u++ ){
    if ( color[u] == WHITE ) dfs_visit(u);
  }
  for ( u = 0; u < n; u++ ){
    printf("%d %d %d\n", u+1, d[u], f[u]);
  }
}


main(){
  int u, k, v, i, j;

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) M[i][j] = 0;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  dfs();

  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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

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

int main()
{	
    ll n, q;
    cin >> n;
    map<ll, ll> mp;
    REP(i, n){
        ll a;
        cin >> a;
        mp[a]++;
    }
    cin >> q;
    ll allsum = 0;
    for(auto p : mp) allsum += p.first * p.second;
    ll sum = allsum;
    
    REP(i, q){
        ll b, c;
        cin >> b >> c;
        sum = sum-mp[b]*b+mp[b]*c;
      	mp[c] += mp[b];
      	mp[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9444
N = int(input())
C = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in range(N):
    c = input()
    if c == "AC":
        C["AC"] += 1
    elif c == "WA":
        C["WA"] += 1
    elif c == "RE":
        C["RE"] += 1
    else:
        C["TLE"] += 1
print("AC x", C["AC"])
print("WA x", C["WA"])
print("TLE x", C["TLE"])
print("RE x", C["RE"])

Measured memory_bytes: 9212
data=[list(map(int,input().split())) for _ in range(4)]
n=0
while n<4:
    t=data[n][0]
    s=data[n][1]
    if t==1:
        print(6000*s)
        n+=1
    if t==2:
        print(4000*s)
        n+=1
    if t==3:
        print(3000*s)
        n+=1
    if t==4:
        print(2000*s)
        n+=1



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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;

int d;
int c[26];
int s[365][26];

int t[365];

int score(){
	int last[26] = {0};
	int evl = 0;

	for( int i = 1; i <= d; i++ ){
		last[t[i-1]-1] = i;
		evl += s[i-1][t[i-1]-1];
		for( int j = 0; j < 26; j++ ){
			evl -= c[j]*(i - last[j]);
		}

		cout << evl << endl;
	}

	return evl;
}

int main(){
	cin >> d;
	for( int i = 0; i < 26; i++ ){
		cin >> c[i];
	}
	for( int i = 0; i < d; i++ ){
		for( int j = 0; j < 26; j++ ){
			cin >> s[i][j];
		}
	}

	for( int i = 0; i < d; i++ ){
		cin >> t[i];
	}

	score();

/*
	int gre;

	for( int i = 0; i < d; i++ ){
		gre = 0;
		for( int j = 0; j < 26; j++ ){
			gre = max( gre, s[i][j] );
			if( gre == s[i][j] ){
				t[i] = j + 1;
			}
		}
	}

	for( int i = 0; i < 365; i++ ){

	}


	for( int i = 0; i < d; i++ ){
		cout << t[i] << endl;
	}
*/

//	cout << "score:" << bscore << endl;

	return 0;
}


Measured memory_bytes: 3656
package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}



Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};


int main()
{
    int N;
    cin >> N;
    int tmp;
    int mini = 1 << 10;
    int maxi = 0;
    for(int i = 0;i < N;i++)
    {
        cin >> tmp;
        maxi = max(maxi,tmp);
        mini = min(mini,tmp);
    }
    cout << maxi - mini << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re register
#define LL long long
#define SIZE 105
#define MOD 1000000007
using namespace std;
int n,k;
LL a[SIZE],dp[SIZE][100005];
LL sum[SIZE][100005];
int main()
{	
    cin>>n>>k;
    for(re int i=1;i<=n;++i)
    	cin>>a[i];
    for(re int i=0;i<=k;++i)
    	sum[0][i]=1;
	for(re LL i=1;i<=n;++i)
		for(re LL j=0;j<=k;++j)
		{
			if(j-min(a[i],j)-1<0)
				(dp[i][j]+=sum[i-1][j]%MOD)%MOD;
			else
				(dp[i][j]+=(sum[i-1][j]%MOD-sum[i-1][j-min(a[i],j)-1]%MOD+MOD)%MOD)%MOD;
			if(j-1<0)
				sum[i][j]=dp[i][j]%MOD;
			else
				(sum[i][j]=sum[i][j-1]%MOD+dp[i][j]%MOD)%MOD;
		}
	cout<<dp[n][k]%MOD<<endl;		
    return 0;
}

Measured memory_bytes: 160000
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int t = (a+d-1)/d;
    int ao = (c+b-1)/b;

    dump(t);

    if(t>=ao){
        cout << "Yes" << endl;
    } 
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
int main()
{
	int a,b;
	std::cin >> a >> b;
	if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0)
	{
		std::cout << "Possible" << std::endl;
	}
	else
	{
		std::cout << "Impossible" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
x,y = list(map(int,input().split()))

mod = 10**9 + 7

# import math
# def comb(n,r):
#     return (math.factorial(n)//(math.factorial(n-r)*math.factorial(r)))

# def comb(n, r, mod):
#     if ( r<0 or r>n ):
#         return 0
#     r = min(r, n-r)
#     return g1[n] * g2[r] * g2[n-r] % mod

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)


# def comb(n,r,mod):
# 	'''
# 	return nCr
# 	O(min{n-r, r})
# 	'''
# 	a=1
# 	b=1
# 	r = min(r,n-r)
# 	for i in range(r):
# 		a = a*(n-i)%mod
# 		b = b*(i+1)%mod
# 	return a*pow(b,mod-2,mod)%mod

if (x+y)%3!=0:
    print(0)
    exit()
else:
    m = int((2*x - y)/3)
    n = int((2*y - x)/3)
    if n>=0 and m>=0:
        print(comb_mod(n+m,n,mod))
        exit()
    else:
        print(0)
        exit()

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

namespace _0228
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] disp = new int[] { 63, 6, 91, 79, 102, 109, 125, 39, 127, 111 };

            while (true)
            {
                int n = RInt();
                if (n == -1) break;

                int before = 0;
                for (int i = 0; i < n; i++)
                {
                    int d = RInt();
                    Console.WriteLine(Convert.ToString(before ^ disp[d], 2).PadLeft(7, '0'));
                    before = disp[d];
                }
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 13872
#include <iostream>
#include <vector>
#include <algorithm>
std::vector<int> twin_primes(int upper) {
	std::vector<bool> suspects(upper + 1, true);
	suspects[0] = suspects[1] = false;
	std::vector<int> res;
	for (auto i = 2; i <= upper; ++i) {
		if (suspects[i]) {
			if (suspects[i - 2])
				res.push_back(i);
			for (auto j = 2 * i; j <= upper; j += i)
				suspects[j] = false;
		}
	}
	return res;
}
int main() {
	int n;
	std::cin >> n;
	auto primes = twin_primes(10000);
	while (n != 0) {
		auto prime = *(std::upper_bound(primes.begin(), primes.end(), n) - 1);
		std::cout << prime - 2 << ' ' << prime << std::endl;
		std::cin >> n;
	}
}


Measured memory_bytes: 3108
N = int(input())
count = 0
for i in range(N):
  D1, D2 = list(map(int, input().split()))
  if(D1 == D2):
    count += 1
  else:
    count = 0
  if(count >= 3):
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 62468
//atCoder C - Reconciled
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
inline int readIn(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
const int MOD = 1e9 + 7;
const int MAX = 100000 + 3;
int n, m;
ll ans;
ll f[MAX];

inline void prepare(){
	f[0] = 1;
	for(int i = 1; i <= MAX - 2; ++i) f[i] = f[i - 1] * i % MOD;
}

int main()
{
#ifdef DBEUG
	freopen("test.in", "r", stdin);
#endif
    prepare();
    n = readIn(), m = readIn();
    if(abs(n - m) > 1) {
    	printf("0\n");
    	return 0;
    }
    else{
    	if(n == m) ans = f[n] * f[m] * 2 % MOD;
    	else if(abs(n - m) == 1) ans = f[n] * f[m] % MOD;
    	printf("%lld\n", (ans % MOD + MOD) % MOD);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fe first
#define se second
#define endl "\n"
#define pii pair<int, int>

#define PI 3.14159265358979323846
const int N = 3005 + 10;
ll dp[N][N];

void solve() {
 int n;
 cin>>n;
 vector<int> a(n);
 for(int i=0;i<n;i++)
    cin>>a[i];
 
 
 
 for(int  i=n-1;i>=0;i--) {
	  for(int j=i;j<n;j++) {
		    if(i==j)
		      dp[i][j]=a[i];
		   else
		      dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);   
		  }
	 
	 }
	 
	 cout<<dp[0][n-1];
	 
	 
}
int main() {
  cool;
  int t = 1;
  while (t--)
    solve();

  return 0;
}


Measured memory_bytes: 70144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  vector<ll> s(n+1);
  rep(i,n){
    s[i+1]=s[i]+a[i];
  }
  vector<bool> f(n+1);
  for(int i=1;i<n;i++){
    if(s[i]*2>=a[i]) f[i]=1;
  }
  f[n]=1;
  int ans=0;
  for(int i=n;i>0;i--){
    if(f[i]) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>

using namespace std;
int main()
{
    string num;
    int i,k=0;
    cin>>num;
    for(i=0;i<3;i++){
        if(num[i]=='7'){
            k=1;
            break;
        }
    }
    if(k){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3592
using System;
using System.Linq;

namespace Program
{
    class A
    {
        static void Main(string[] args)
        {
            var ND = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = ND[0];
            var D = ND[1];
            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                var XY = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var dis = Math.Sqrt(Math.Pow(XY[0],2) + Math.Pow(XY[1],2));
                if(dis <= D)
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 47092
import java.util.*
import java.math.*

fun main(args: Array<String>) {
    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val S = readLine()!!
//    val D = readLine()!!.split(" ").map { it.toLong() }

    println(N-K+1)
}


Measured memory_bytes: 37544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int MAX = 2001;
int N, K;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void solve() {
    COMinit();
    cin >> N >> K;
    int RN = N - K + 1;
    for (int i = 1; i <= K; ++i) {
        if (RN < i) cout << 0 << endl;
        else {
            ll x = COM(RN, i);
            ll y = COM(K-1, i-1);
            cout << x * y % MOD << endl;
        }
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
if m==0:
  print("{} {}".format(0,0))
else:
  ac_count=0
  wa_count=0
  ac_list=[0]*n
  wa_list=[0]*n
  for i in range(m):
    p,s=input().split()
    if ac_list[int(p)-1]==0:
      if s=="AC":
        ac_count+=1
        ac_list[int(p)-1]+=1
      else:
        wa_list[int(p)-1]+=1
  for k in range(n):
    if ac_list[k]==1:
      wa_count+=wa_list[k]
  print("{} {}".format(ac_count,wa_count))

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

using namespace std;
using ll = long long;
ll a[200005];
const ll mod = 1e9 + 7;
ll qpow(ll x,ll n,ll mod)
{
    ll res =1;
    while(n>0)
    {
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    ll n;
    cin >> n;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
        sum %= mod;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll tmp = sum - a[i];
        tmp += mod;
        tmp %= mod;
        ans += a[i] * tmp;
        ans %= mod;
    }
    ans *= qpow(2, mod - 2, mod);
    ans %= mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5168
#include<stdio.h>

int main(void)
{
    int i, j;
    int t[6], d[6];
    enum dir {UP, FRONT, RIGHT, LEFT, BACK, DOWN};
    
    for ( i=0; i<6; ++i)
        scanf("%d", &t[i]);
    for ( i=0; i<6; ++i)
        scanf("%d", &d[i]);
        
    if ( t[0]==d[UP] && t[5]==d[DOWN]) {
        if ( (t[1]==d[FRONT] && t[2]==d[RIGHT] && t[4]==d[BACK] && t[3]==d[LEFT])
          || (t[2]==d[FRONT] && t[4]==d[RIGHT] && t[3]==d[BACK] && t[1]==d[LEFT])
          || (t[4]==d[FRONT] && t[3]==d[RIGHT] && t[1]==d[BACK] && t[2]==d[LEFT])
          || (t[3]==d[FRONT] && t[1]==d[RIGHT] && t[2]==d[BACK] && t[4]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else if ( t[1]==d[UP] && t[4]==d[DOWN]) {
        if ( (t[0]==d[FRONT] && t[3]==d[RIGHT] && t[5]==d[BACK] && t[2]==d[LEFT])
          || (t[3]==d[FRONT] && t[5]==d[RIGHT] && t[2]==d[BACK] && t[0]==d[LEFT])
          || (t[5]==d[FRONT] && t[2]==d[RIGHT] && t[0]==d[BACK] && t[3]==d[LEFT])
          || (t[2]==d[FRONT] && t[0]==d[RIGHT] && t[3]==d[BACK] && t[5]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else if ( t[2]==d[UP] && t[3]==d[DOWN]) {
        if ( (t[0]==d[FRONT] && t[1]==d[RIGHT] && t[5]==d[BACK] && t[4]==d[LEFT])
          || (t[1]==d[FRONT] && t[5]==d[RIGHT] && t[4]==d[BACK] && t[0]==d[LEFT])
          || (t[5]==d[FRONT] && t[4]==d[RIGHT] && t[0]==d[BACK] && t[1]==d[LEFT])
          || (t[4]==d[FRONT] && t[0]==d[RIGHT] && t[1]==d[BACK] && t[5]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else if ( t[3]==d[UP] && t[2]==d[DOWN]) {
        if ( (t[0]==d[FRONT] && t[4]==d[RIGHT] && t[5]==d[BACK] && t[1]==d[LEFT])
          || (t[4]==d[FRONT] && t[5]==d[RIGHT] && t[1]==d[BACK] && t[0]==d[LEFT])
          || (t[5]==d[FRONT] && t[1]==d[RIGHT] && t[0]==d[BACK] && t[4]==d[LEFT])
          || (t[1]==d[FRONT] && t[0]==d[RIGHT] && t[4]==d[BACK] && t[5]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else if ( t[4]==d[UP] && t[1]==d[DOWN]) {
        if ( (t[0]==d[FRONT] && t[2]==d[RIGHT] && t[5]==d[BACK] && t[3]==d[LEFT])
          || (t[2]==d[FRONT] && t[5]==d[RIGHT] && t[3]==d[BACK] && t[0]==d[LEFT])
          || (t[5]==d[FRONT] && t[3]==d[RIGHT] && t[0]==d[BACK] && t[2]==d[LEFT])
          || (t[3]==d[FRONT] && t[0]==d[RIGHT] && t[2]==d[BACK] && t[5]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else if ( t[5]==d[UP] && t[0]==d[DOWN]) {
        if ( (t[1]==d[FRONT] && t[3]==d[RIGHT] && t[4]==d[BACK] && t[2]==d[LEFT])
          || (t[3]==d[FRONT] && t[4]==d[RIGHT] && t[2]==d[BACK] && t[1]==d[LEFT])
          || (t[4]==d[FRONT] && t[2]==d[RIGHT] && t[1]==d[BACK] && t[3]==d[LEFT])
          || (t[2]==d[FRONT] && t[1]==d[RIGHT] && t[3]==d[BACK] && t[4]==d[LEFT]) )
            printf("Yes\n");
        else
            printf("No\n");
    }else
        printf("No\n");
    
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
    int max = 0;
    string s,longests,frequents;
    map<string,int> dict;
    while(cin >>s){
        dict[s] +=1;
        if(s.size() >= max){
            longests = s;
            max = s.size();
        }
        if(dict[s] >= dict[frequents]){
            frequents = s;
        }
    }
    cout << frequents << " " << longests << endl;
}

Measured memory_bytes: 1192
#include<cstdio>
const int N=1000005;
int n,he[128],nx[N],a,qu[N*2],hd,tl,d;char s[N],t[N];
inline int mx(int x,int y){return x>y?x:y;}
int main()
{
	scanf("%d%s%s",&n,s+1,t+1),hd=n+1,tl=n;
	for(int i=1;i<=n;++i)nx[i]=he[s[i]],he[s[i]]=i;
	for(int i=n;i;--i)
	{
		if(hd>tl||i<qu[hd]-d)
		{
			hd=n+1,tl=n,d=0;
			if(s[i]!=t[i])
			{
				for(;he[t[i]]&&he[t[i]]>=i;he[t[i]]=nx[he[t[i]]]);
				if(!he[t[i]])return printf("-1"),0;
				qu[--hd]=he[t[i]],qu[++tl]=i;
			}
		}
		else
		{
			if(s[qu[hd]-d]!=t[i])
			{
				for(;he[t[i]]&&he[t[i]]>=qu[hd]-d;he[t[i]]=nx[he[t[i]]]);
				if(!he[t[i]])return printf("-1"),0;
				for(;qu[tl]-d>i;--tl);++d,qu[--hd]=he[t[i]]+d,qu[++tl]=i+d;
			}
		}
		a=mx(a,tl-hd);
	}
	printf("%d",a);
	return 0;
}

Measured memory_bytes: 11448
circleInRectangle :: [Int] -> String
circleInRectangle [w, h, x, y, r] | y - r < 0 = "No"
                            | x - r < 0 = "No"
                            | y + r > h = "No"
                            | x + r > w = "No"
                            | otherwise = "Yes"
main = do putStrLn . circleInRectangle . map read . words =<< getLine

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
   int ma1, ma2, mi1, mi2, a, b, ans;
   cin >> a >> b;
   a*=100;
   b*=100;
   mi1=a/8;
   if(a%8!=0) mi1++;
   mi2=b/10;
   if(b%10!=0) mi2++;
   ma1=(a+100)/8;
   if((a+100)%8==0) ma1--;
   ma2=(b+100)/10;
   if((b+100)%10==0) ma2--;
   if(mi1==mi2) ans=mi1;
   else if(mi1<mi2){
       if(ma1<mi2) ans = -1;
       else ans = mi2;
   }else{
       if(ma2<mi1) ans=-1;
       else ans = mi1;
   }
   cout << ans << endl;
}
    




Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]

def solve(s):
  ans, tmp = 0, 0
  for i in range(N):
    tmp += A[i]
    if tmp * s <= 0:
      ans += abs(tmp - s)
      tmp = s
    s *= -1
  return ans
print(min(solve(1), solve(-1)))

Measured memory_bytes: 14212
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+1000;
int n,x,y;
int a[maxn];
int b[maxn];
int c[maxn]; 
long long sum;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=1;i<=n;i++) scanf("%d",&c[i]);
	sort(a+1,a+n+1);
	sort(c+1,c+n+1); 
	for (int i=1;i<=n;i++)
	{
		x=lower_bound(a+1,a+n+1,b[i])-a;
		x--;
		y=upper_bound(c+1,c+n+1,b[i])-c;
		sum+=(long long)x*(long long)(n-y+1);
	}
	cout<<sum;
	return 0;
}  

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long int b[100001],pre[1000001],a[100001];
int main() {
    long long n,m,x;
    cin>>n>>x>>m;
    long long ans=pre[1]=a[1]=x;
    b[x]=1;
	for (int i=2;i<=n;i++){
		a[i]=a[i-1]*a[i-1]%m;
		ans=pre[i]=pre[i-1]+a[i];
		if (b[a[i]]>0) {
			long long t1=(n-b[a[i]])/(i-b[a[i]]),t2=(n-b[a[i]])%(i-b[a[i]]);
			ans=pre[b[a[i]]+t2]+(pre[i]-pre[b[a[i]]])*t1;
			break;
		}
		b[a[i]]=i;
	}    
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5140
import java.util.*;

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[] dp = new int[n + 1];
      dp[0] = 1;

      for(int i = 0; i < n; i++){
        for(int j = 1; j <= 3; j++){
          if(n < i + j) break;
          dp[i + j] += dp[i];
        }
      }

      System.out.println((((dp[n] + 9) / 10) - 1) / 365 + 1);
    }
  }
}

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

int main(){
  int n,k,i,a;
  cin >> n >> k;
  vector<int> x(n+1,0);
  for(i=0;i<n;i++){
    cin >> a;
    x.at(a)++;
  }
  
  sort(x.begin(),x.end());
  int s=0;
  for(i=0;i<=n-k;i++){
    s += x.at(i);
  }
  cout << s << endl;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[200010];
int sum[200010];
signed main()
{
    int n, k;
    cin >> n >> k;
    REP(i,n) {
        cin >> a[i];
        a[i] %= k;
        sum[i + 1] = a[i] + sum[i];
    }
    map<int, int> mp;
    int ans = 0;
    for (int j = 0; j <= n; j++)
    {
        if(j-k>=0)
            mp[(sum[j - k] - (j - k)) % k]--;

        ans += mp[(sum[j] - j) % k];
        mp[(sum[j] - j) % k]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)






#define MAX_V 100
struct edge { int to, cap, cost,rev; };

int V; // ????????°
vector<edge> G[MAX_V];
vector<int> h(MAX_V);	//??????????????£???
vector<int> dist(MAX_V);// ???????????¢
int prevv[MAX_V], preve[MAX_V];// ??´??????????????¨???

// from??????to??????????????????cap????????????cost????????????????????????????????????
void add_edge(int from, int to, int cap, int cost) {
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}


//?????????????????????????????????????????´????????????
void shortest_path(int s,vector<int> &d){
	int v = d.size();
	rep(i,d.size())d[i]=INF;
	d[s]=0;
	rep(loop,v){
		rep(i,v){
			rep(j,G[i].size()){
				edge e = G[i][j];
				if(!e.cap)continue;
				if(d[i]!=INF && d[e.to] > d[i]+e.cost){
					d[e.to] = d[i]+e.cost;
					preve[e.to]=j;
				}
			}
		}
	}
}


// s??????t????????????f???????°??????¨???????±???????
// ??????????????´??????-1?????????
int min_cost_flow(int s, int t, int f) {
	int res = 0;
	shortest_path(s, h);
	
	while (f > 0) {
		// ?????????????????????????????¨??????h?????´??°??????
		priority_queue<pii, vector<pii>, greater<pii> > que;
		rep(i,dist.size())dist[i]=INF;
		dist[s] = 0;
		que.push(pii(0, s));
		while (!que.empty()) {
			pii p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v;
					preve[e.to] = i;
					que.push(pii(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) return -1;	//????????\???????????????
		
		for (int v = 0; v < V; v++) h[v] += dist[v];
		
		
		// s-t????????????????????£??????????????????
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]]; e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(){
	int e,f;
	cin>>V>>e>>f;
	rep(i,e){
		int u,v,c,d;
		cin>>u>>v>>c>>d;
		add_edge(u, v, c, d);
	}
	cout<<min_cost_flow(0, V-1, f)<<endl;
}

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

int main() {
    std::string S;
    std::cin >> S;
    int ans = 0;
    if (S == "SUN") {
        ans = 7;
    } else if (S == "MON") {
        ans = 6;
    } else if (S == "TUE") {
        ans = 5;
    } else if (S == "WED") {
        ans = 4;
    } else if (S == "THU") {
        ans = 3;
    } else if (S == "FRI") {
        ans = 2;
    } else if (S == "SAT") {
        ans = 1;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int p,q;
	while(cin >> p >> q,p){
		vector<pair<pair<int,int>,pair<int,int>>> vv(p);
		int x=0,y=0,z=0;
		for(int i=0;i<p;i++){
			string s; cin >> s;
			int id=0;
			while(id<s.size()&&s[id]=='.')id++;
			vv[i]=make_pair(make_pair(x,y),make_pair(z,id));
			for(char c:s){
				if(c=='(')x++;
				if(c==')')x--;
				if(c=='{')y++;
				if(c=='}')y--;
				if(c=='[')z++;
				if(c==']')z--;
			}
		}
		vector<pair<int,pair<int,int>>> v;
		for(int i=1;i<=20;i++){
			for(int j=1;j<=20;j++){
				for(int k=1;k<=20;k++){
					bool ok=1;
					for(auto p:vv){
						if(!ok)break;
						if(p.first.first*i+p.first.second*j+p.second.first*k!=p.second.second)ok=0;
					}
					if(ok){
						v.push_back(make_pair(i,make_pair(j,k)));
					}
				}
			}
		}
		x=0,y=0,z=0;
		for(int i=0;i<q;i++){
			if(i)printf(" ");
			string s; cin >> s;
			set<int> st;
			for(auto p:v){
				st.insert(x*p.first+y*p.second.first+z*p.second.second);
			}
			if(st.size()==1){
				printf("%d",*st.begin());
			}
			else{
				printf("-1");
			}
			for(char c:s){
				if(c=='(')x++;
				if(c==')')x--;
				if(c=='{')y++;
				if(c=='}')y--;
				if(c=='[')z++;
				if(c==']')z--;
			}
		}
		printf("\n");
	}
}


Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr,int> ppr;
typedef vector<pr> vpr;
int maps[2][5001];
typedef priority_queue<ppr,vector<ppr>,greater<ppr> > pq;
//inline int max(int a,int b){return (a<b)?b:a;}
int main() {
	int N,M,x,y,size;
	pq nail;
	
	cin >> N >> M;
	REP(i,M){
		scanf("%d%d%d",&x,&y,&size);
		nail.push(ppr(pr(x,y) , size+1));
	}
	int sum=0;
	REP(i,N+1){
		REP(j,N+1)
			maps[(i+1)&1][j]=0;
		while(!nail.empty() &&nail.top().first.first==i){
			maps[i&1][nail.top().first.second]=max(maps[i&1][nail.top().first.second],nail.top().second);
			nail.pop();
		}
		REP(j,N+1){
			maps[(i+1)&1][j+1]=max(maps[(i+1)&1][j+1],maps[i&1][j]-1);
			maps[(i+1)&1][j]=max(maps[(i+1)&1][j],maps[i&1][j]-1);
			if(maps[i&1][j])
				sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string b;
  cin >> b;
  if(b=="A"){
    cout << "T" << endl;
  }
  else if(b=="T"){
    cout << "A" << endl;
  }
  else if(b=="C"){
    cout << "G" << endl;
  }
  else if(b=="G"){
    cout << "C" << endl;
  }
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

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

   int sum = 0;
   map<int,int>m;

   f(i,0,n){
      int a;
      cin >> a;
      sum += a;
      m[a]++;
   }

   int q;
   cin >> q;
   while(q--){
      int b,c;
      cin >> b >> c;
      sum += (c - b) * m[b];
      m[c] += m[b];
      m[b] = 0;

      cout << sum << "\n";
   }
}

Measured memory_bytes: 9560
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;

bool check(int a[3]){
	if(a[0]==a[1] || a[1]==a[2] || a[0]==a[2]){
		return false;
	}
	sort(a, a+3);
	if(a[0]+a[1]>a[2]){
		return true;
	}else{
		return false;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	
	int ans=0;
	for(int i=0; i<n-2; i++){
		for(int j=i+1; j<n-1; j++){
			for(int k=j+1; k<n; k++){
				int temp[3] = {a[i], a[j], a[k]};
				ans+=check(temp);
			}
		}
	}
	cout << ans;
	
}





Measured memory_bytes: 3684
N, *A = map(int, open(0).read().split())

count = 0
for i in range(N):
    min_j = i
    for j in range(i, N):
        if A[j] < A[min_j]: 
            min_j = j
    if min_j != i:
        A[i], A[min_j] = A[min_j], A[i]
        count += 1

print(' '.join([str(a) for a in A]))
print(count)


Measured memory_bytes: 5604
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,tmp;
    int i;
    int min=1000000,max=-1000000;
    int long add=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&tmp);
        if(tmp<min){
            min=tmp;
        }if(max<tmp){
            max=tmp;
        }add=add+tmp;
        
    }
    printf("%d %d %ld\n",min,max,add);
    return 0;
}

Measured memory_bytes: 600
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<BigInteger> num = new ArrayList<BigInteger>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextBigInteger()) {
				num.add(sc.nextBigInteger());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<BigInteger> num, ArrayList<String> param) {
		BigInteger ze = new BigInteger("0");

		if(num.get(0).compareTo(BigInteger.ZERO) == 0 && num.get(2).compareTo(BigInteger.ONE) != 0) ze = ze.add(BigInteger.ONE);
		System.out.println(num.get(1).divide(num.get(2)).subtract((num.get(0).subtract(BigInteger.ONE)).divide(num.get(2))).add(ze));
	}
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll k,n;
	cin >> k >> n;

	if(k%2 == 0){
		cout << (k/2);
		rep(i,n-1) cout << " " << k;
		cout << endl;
	}else{
		vector<ll> b(n,(k+1)/2);
		rep(i,n/2){
			if(b[b.size()-1] == 1){
				b.pop_back();
			}else{
				b[b.size()-1]--;
				while(b.size() < n) b.push_back(k);
			}
		}
		rep(i,b.size()){
			cout << b[i] << (i == b.size()-1 ? "\n" : " ");
		}
	}
}

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

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

    int sumt = 0;
    int mint = 100;
    for (int i=1; i<=N; i++) {
        int t = (L + i - 1);
        if (abs(t) < abs(mint)) {
            mint = t;
        }
        sumt += t;
    }

    cout << (sumt - mint) << endl;

    return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll,ll> > vpll;
typedef vector< vector<int> > matrix;

#define SET(Ar,val) memset(Ar,val,sizeof(Ar))
#define rep(i,val,n)  for(int i=val;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a,T b,T MOD)
{
    T ans=1;
    while(b!=0)
    {
        if(b%2==1)
        ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return ans;
}

int ar[200005];

void init()
{
    int N,x;
    cin >> N;
    rep(i,0,N)
    {
        cin >> x ;
        ar[x] = (i+1);
    }
    int maxcnt = 1,Ccnt = 1;
    rep(i,2,N+1)
    {
        if(ar[i] > ar[i-1])
        {
            Ccnt++;
            maxcnt = max(maxcnt,Ccnt);
        }
        else
        {
            Ccnt = 1;
        }
    }
    cout << N - maxcnt ;
}

int main()
{
    clock_t time1=clock();
	/*#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	#else
	//ONLINE_JUDGE
	#endif*/
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    init();
    clock_t time2 = clock();
    cerr <<"Time: " <<(double)(time2-time1)/CLOCKS_PER_SEC <<" seconds" <<endl;
	return 0;
}


Measured memory_bytes: 1024