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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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



signed main() {

    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<set<int>> c(M);
    vector<P> cheapkey(N, {INF,-1});   //箱iをあけられる安い鍵の値段と番号
    rep(i, M) {
        int b; cin >> a[i] >> b;
        rep(j, b) {
            int cc; cin >> cc; cc--;
            c[i].insert(cc);
            cheapkey[cc] = min(cheapkey[cc], { a[i],i });
        }
    }
    rep(i, N) {
        if (cheapkey[i].first == INF) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> dp(1LL << N, INF);
    dp[0] = 0;

    for (int s = 0; s < (1LL << N); s++) {
        for (int key = 0; key < M; key++) {
            int mask=0;
            for (int b : c[key]) mask |= 1 << b;
            dp[s | mask] = min(dp[s|mask], dp[s] + a[key]);
        }
    }

    cout << dp[(1LL<<N)-1] << endl;

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

bool shichigosan(int i)
{
    bool seven = false;
    bool five = false;
    bool three = false;
    while (i > 0)
    {
        auto j = i % 10;
        if (j == 7)
        {
            seven = true;
        }
        else if (j == 5)
        {
            five = true;
        }
        else if (j == 3)
        {
            three = true;
        }
        else
        {
            return false;
        }
        i /= 10;
    }

    return seven && five && three;
}

template <class T>
T combination(T n, T r)
{
    if (n == r || r == 0)
    {
        return 1;
    }
    return combination(n - 1, r - 1) + combination(n - 1, r);
}

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

    int order = int(log10(N)) + 1;
    int n = N / static_cast<int>(pow(10, order));

    int lut[3] = {7, 5, 3};
    int count = 0;
    for (int o = 3; o <= order; ++o)
    {
        for (int i = 0; i < pow(3, o); ++i)
        {
            vector<int> v;
            int k = i;
            for (int j = 0; j < o; ++j)
            {
                v.push_back(k % 3);
                k /= 3;
            }

            int l = 0;
            for (auto m : v)
            {
                l *= 10;
                l += lut[m];
            }

            if (l <= N && shichigosan(l))
            {
                //                cout << l << endl;
                ++count;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 384
n,x = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
a.sort()

for i in range(n):
  if x - a[i] >= 0:
    cnt += 1
    x -= a[i]
  else:
    break
if x == 0 or cnt < n:
  print(cnt)
else:
  print(cnt-1)

Measured memory_bytes: 3060
antenas = [int(input()),int(input()),int(input()),int(input()),int(input())]
k = int(input())
flg = False

for i in antenas:
    for j in antenas:
        flg = abs(j - i) > k
        if flg:
            break

if flg:
    print(":(")
else:
    print("Yay!")



Measured memory_bytes: 3060
#include <stdio.h>
#include <limits.h>

int main(void)
{
	int array[5000], n, i, j, sum, max;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		max = INT_MIN;
		
		for (i = 0; i < n; i++){
			scanf("%d", &array[i]);
		}
		
		for (i = 0; i < n; i++){
			sum = 0;
			for (j = i; j < n; j++){
				sum += array[j];
				
				if (max < sum){
					max = sum;
				}
			}
		}
		
		printf("%d\n", max);
	}
	
	return (0);
}

Measured memory_bytes: 616
#include<iostream>

using namespace std;

int main() {
	int a, b, ans = 0, ans1, m;
	while(cin>>m) {
		while(m--) {
			cin>>a;
			cin>>b;
			if(a>ans) {
				ans = a;
				ans1 = b;
			}
		}
		cout<<ans+ans1<<endl;
		ans = 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){

    long long day = 5000000000000000;

    string S;
    long long K;
    cin >> S >> K;

    char zero = '0';
    int ans;

    for (int i = 0; i < S.length(); i++){
        int a = S[i] - zero;

        K -= std::pow(a, day);

        if (K <= 0){
            ans = a;
            break;
        }    
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    if(N == 2) {
        if(K == 0) {
            cout << 1 << endl;
            cout << 1 << " " << 2 << endl;
        } else {
            cout << -1 << endl;
        }
    } else if(K > (N - 1) * (N - 2) / 2) {
        cout << -1 << endl;
    } else {
        int rem = (N - 1) * (N - 2) / 2 - K;
        cout << N - 1 + rem << endl;

        rep(i, 2, N + 1) { cout << 1 << " " << i << endl; }

        rep(i, 2, N + 1) {
            if(rem == 0) {
                break;
            }
            rep(r, i + 1, N + 1) {
                cout << i << " " << r << endl;
                rem--;
                if(rem == 0) {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


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

  string s;
  long k;
  cin >> s >> k;

  long cntK = 0;
  bool isFk = false;
  for(int i = 1; i < s.size(); i++) {
    if (s[i] == s[i-1]) {
      if (i == s.size() - 1) isFk = true;
      cntK++;
      i++;
    }
  }

  long cntG = 0;
  int i;
  bool isFk2 = false;
  if (!isFk && s[0] == s[s.size()-1]) {
    i = 2;
    cntG++;
    if (s.size() == 1) isFk2 = true;
  } else {
    i = 1;
  }
  for(; i < s.size(); i++) {
    if (s[i] == s[i-1]) {
      if (i == s.size() - 1) isFk2 = true;
      cntG++;
      i++;
    }
  }

  long res;
  if (!isFk2 && s[0] == s[s.size()-1]) {
    res = cntK + cntG * (k-1);
  } else {
    res = cntK * ((k+1)/2) + cntG * (k/2);
  }

  cout << res << endl;
}


Measured memory_bytes: 888
# https://atcoder.jp/contests/abc106/tasks/abc106_b
import math

N = int(input())


def is_8(num):
    if num < 1:
        return False
    elif num == 1:
        return False
    else:
        divisor_list = set()
        divisor_list.add(1)
        # root nまで見れば問題ない
        for i in range(2, int(math.sqrt(num)) + 1):
            if num % i == 0:
                divisor_list.add(num // i)
                divisor_list.add(i)
        # 元の数を入れる
        divisor_list.add(num)
        if len(divisor_list) == 8:
            return True

cnt = 0
for i in range(1, N + 1, 2):
    if is_8(i):
        cnt += 1

print(cnt)


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

typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  friend ostream& operator<<(ostream& os, const ModInt& mi) { os << mi.val; return os; }
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<998244353>;
#endif

modint dp[3001][3001];
int main() {
  int n, s; cin >> n >> s;
  modint i2 = 1;
  for (int i = 0; i < n; ++i) { 
    int a; cin >> a;
    for (int j = 0; j <= s; ++j) { 
      dp[i+1][j] += dp[i][j]*modint(2);
      if (j+a > s) continue;
      dp[i+1][j+a] += dp[i][j];
    }
    dp[i+1][a] += i2;
    // cout << i2 << " " << dp[i+1][2] << " " << dp[i+1][4] << endl;
    i2 *= 2;
  }
  cout << dp[n][s] << endl;
}


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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))


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

template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }

using namespace std;

int total[100005];
int zero[100005];

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

	string s;
	cin >> s;

	vector<pair<int, int>> items;
	items.push_back({ 0,0 });

	char c = s[0];
	int last = 0;

	int i = 0;

	for (i = 0; i < (int)s.size(); i++)
	{
		if (c != s[i])
		{
			items.push_back({ i - last,c - '0' });
			last = i;
		}

		c = s[i];
	}

	items.push_back({ i - last,c - '0' });
	last = i;

	

	for (i = 1; i < (int)items.size(); i++)
	{
		total[i] = items[i].first;
		total[i] += total[i - 1];

		if (items[i].second == 0)
			zero[i] = 1;

		zero[i] += zero[i - 1];
	}

	i = 1;
	int j = 1;
	int mx = 0;

	while (j < (int)items.size())
	{
		mx = max(mx, total[j] - total[i - 1]);

		j++;

		while (zero[j]-zero[i-1]>k)
		{
			i++;
		}

		mx = max(mx, total[j] - total[i - 1]);
	}

	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 2036
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;

    if (A == B) {
        cout << C << endl;
    } else if (B == C) {
        cout << A << endl;

    } else if (C == A) {
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int ans = 0;
		int tmpAns = 0;
		boolean onCount = false;

		List<String> inputList = Arrays.asList(S.split(""));

		List<String> acgtList = new ArrayList<>();
		acgtList.add("A");
		acgtList.add("C");
		acgtList.add("G");
		acgtList.add("T");

		for(int i=0; i<inputList.size(); i++){
			if(acgtList.contains(inputList.get(i))){
				onCount = true;
				tmpAns++;
			} else{
				if(onCount){
					if(tmpAns > ans){
						ans = tmpAns;
					}
				}
				onCount = false;
				tmpAns = 0;
			}
		}

		if(tmpAns > ans){
			ans = tmpAns;
		}


        System.out.println(ans);


	}

}



Measured memory_bytes: 23636
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = int.Parse(ReadLine());
            int x = (int)Sqrt(s) + 1;
            int[] ans = new int[s];
            for (int i = 1; i < x; i++)
            {
                for (int j = 1; j < x; j++)
                {
                    for (int k = 1; k < x; k++)
                    {
                        int result = (i + j + k) * (i + j + k) - (i * j + k * i + j * k);
                        if (result <= s)
                            ans[result - 1]++;
                    }
                }
            }

            for (int i = 0; i < s; i++)
            {
                WriteLine(ans[i]);
                Out.Flush();
            }
        }
    }
}

Measured memory_bytes: 27592
N = int(input())
H = list(map(int, input().split()))[::-1]

pre_h = float('inf')
for h in H:
    if pre_h >= h:
        pre_h = h
    elif pre_h == h-1:
        pre_h = h-1
    else:
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 14224
import itertools
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N=int(input())
S=[input() for i in range(N)]
d={}
#10*N
for i in S:
  s="".join(sorted(i))
  if s in d:
    d[s]+=1
  else:
    d[s]=1  
ans=0
for v in d.values():
  if v>=2:
    ans+=cc(v,2)
print(ans)
  

Measured memory_bytes: 24988
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var s = input.ReadLine();

        int lp = 0;
        int rp = n-1;
        int co = 0;

        while (lp < rp) {
            var c = s[rp];
            if (c == 'R') {
                while (lp < rp) {
                    if (s[lp] == 'W') {
                        break;
                    }
                    lp++;
                }
                if (lp < rp) {
                    //入れ替え
                    lp++;
                    co++;
                }
            }
            if(lp >= rp) {
                break;
            }
            rp--;
        }

        return co;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        if (n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  
  long long int ans = 0;
  map<int, int> count;
  for (int i = 0; i < N; ++i) {
    ans += count[i-A[i]];
    count[i+A[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 21112
N = int(input())

position = []
for n in range(N):
    x, y = map(int, input().split())
    position.append((x, y))

if (N != 1):
    dis_dic = {}
    for n in range(N):
        for m in range(N):
            if (n != m):
                distance_tuple = (position[n][0] - position[m]
                                  [0], position[n][1] - position[m][1])

                if distance_tuple in dis_dic.keys():
                    dis_dic[distance_tuple] += 1
                else:
                    dis_dic[distance_tuple] = 1

    print(N - max(dis_dic.values()))
else:
    print(1)


Measured memory_bytes: 3444
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x[102] , y[102] = {} , h[102] = {};
    rep(n) cin >> x[i] >> y[i] >> h[i];
    rep(n) {
	    if( h[i] ) swap( x[0] , x[i] ) , swap( y[0] , y[i] ) , swap( h[0] , h[i] );
	} 
    rep(101) {
    	rep2( 101 ) {
    		int a = abs(i - x[0]) + abs(j - y[0]) + h[0];
            bool w = false;
            for( int k = 1 ; k < n ; k++ ) {
                if ( max( 0 , a - abs( i - x[k] ) - abs( j - y[k] ) ) != h[k] ) w = true;
            }
            if( w == false ) {
                cout << i << ' ' << j << ' ' << a << endl;
                return 0;
            }
		}
	}
}


Measured memory_bytes: 3656
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

def solve():
    global n, m, sc
    for i in range(1000):
        tmp = str(i)
        if len(tmp) != n:
            continue
        check = True
        for s, c in sc:
            if int(tmp[s-1]) != c:
                check = False
        if check:
            return tmp
    return -1
print(solve())

Measured memory_bytes: 39152
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(0, N):
    w = wv[i][0]
    v = wv[i][1]
    for j in range(W + 1):
        if j - w >= 0:
            dpp = dp[i][j - w] + v
            dp[i + 1][j] = max(dp[i + 1][j], dpp)    
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(max(dp[-1]))

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int total = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    if (x > (K - x)) {
      total += (2 * (K - x));
    }else{
      total += 2 * x;
    }
  }
  
  cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////

ll solve(ll n) {
	if (n % 2 == 1) { return 0; }

	n /= 2;

	ll ans = 0;

	while (n > 0) {
		n /= 5;
		ans += n;
	}

	return ans;

}

	
int main() {

	ll n;
	cin >> n;
	cout << solve(n);
	
	system("PAUSE");
}

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


using namespace std;

int main() {

	int a, b;
	char c;

	while (1) {
		cin >> a >> c >> b;

		if (c == '?') { return 0; }
		else {
			if (c == '+') { cout << a + b << endl; }
			if (c == '-') { cout << a - b << endl; }
			if (c == '*') { cout << a * b << endl; }
			if (c == '/') { cout << int(a / b) << endl; }
		}
	}

}


Measured memory_bytes: 3112
N = int(input())

def ask1(n):
  s = ['?'] + [i for i in range(n,n+N)]
  print(*s)
  return input()

def ask2(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  else:
    s = ['?'] + [a] + [i for i in range(l,r+1)]
  print(*s)
  return input()

def ask3(a,l,r):
  if l == r:
    s = ['?'] + [a] 
  elif l < 1:
    s = ['?'] + [a] + [i for i in range(N+2,N*2+1)]
  elif r > N*2:
    s = ['?'] + [a] + [i for i in range(1,N)]
  else:
    s = ['?'] + [a] + [i for i in range(1,l+1)] + [i for i in range(r,N*2+1)]
  print(*s)
  return input()

#print(ask1(10))
#print(ask2(1,4,7))
#print(ask3(7,4,11))
#exit()

ans = ['' for _ in range(N*2)]

a = ask1(1)
if a == 'Red':
  LC = 'Red'
else:
  LC = 'Blue'

l = 1
r = N+1
while(l+1 < r):
  m = (l+r)//2
  a = ask1(m)
  if a == LC:
    l = m
  else:
    r = m

sl = r
sr = l+N-1
for i in range(1,N*2+1):
  if sl <= i <= sr:
    a = ask3(i,sl-2,sr+2)
  else:
    a = ask2(i,sl,sr)
  if a == 'Red':
    ans[i-1] = 'R'
  else:
    ans[i-1] = 'B'
  
print('! '+''.join(ans))

Measured memory_bytes: 42052
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;


int main() {
  int n; cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));

  ll ans;
  double ma, mb;

  if (n & 1) {
    ma = a[(n - 1) / 2];
    mb = b[(n - 1) / 2];
    ans = abs(ma - mb) + 1;
  } else {
    ma = (a[n / 2] + a[(n - 1) / 2]) / 2.0;
    mb = (b[n / 2] + b[(n - 1) / 2]) / 2.0;
    ans = abs(ma * 2 - mb * 2) + 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char a,b;
  cin >> a >> b;
  if(a=='H' && b=='H')
    cout << "H" << endl;
  else if(a=='D' && b=='H')
    cout << "D" << endl;
  else if(a=='H' && b=='D')
    cout << "D" << endl;
  else if(a=='D' && b=='D')
    cout << "H" << endl;
}

Measured memory_bytes: 256
s = input()
if s == s[::-1]:
    temp = s[0:int(((len(s) - 1) / 2))]
    if temp == temp[::-1]:
        temp = s[int(((len(s) + 3) / 2)) - 1:len(s)]
        if temp == temp[::-1]:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 2940
#include <cstdio>
using namespace std;

int main() 
{
	long long a;
	char buf[5];
	scanf("%lld%s", &a, buf);
	int b = (buf[0] - '0') * 100 + (buf[2] - '0') * 10 + (buf[3] - '0');
	printf("%lld\n", a * b / 100);
	return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i=0; i<2; i++) {
        for (int j=0; j<N; j++) {
            cin>>A[i][j];
        }
    }
    
    
    int low_sum=0;
    for (int j=0; j<N; j++) {
        low_sum+=A[1][j];
    }
    
    int ans=0, high_num=0, low_num=0;
    for (int j=0; j<N; j++) {
        high_num+=A[0][j];
        
        if (ans < (high_num)+(low_sum-low_num)) {
            ans=(high_num)+(low_sum-low_num);
        }
        
        low_num+=A[1][j];
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

long a[200001];
long b[200001];
int bs(int n, long x){
	int l=1, r=n;
	while(l<=r){
		int m=(l+r)/2;
		if(b[m]>x) r=m-1; else l=m+1;
	}
	return l;
}
int main(void){
	int n=nextint();
	int m=nextint();
	int k=nextint();
	for(int i=1; i<=n; i++){
		a[i]=nextint();
		a[i]+=a[i-1];
	}
	for(int i=1; i<=m; i++){
		b[i]=nextint();
		b[i]+=b[i-1];
	}
	int ans=0;
	for(int i=0; i<=n; i++){
		if(a[i]<=k){
			int l=bs(m, k-a[i])-1;
			int now=i+l;
			if(now>ans) ans=now;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 4720
import sys
import itertools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N, M, Q = map(int, readline().split())
    qlist = []
    for _ in range(Q):
        qlist.append(tuple(map(int, readline().split())))

    iters = itertools.combinations_with_replacement(range(1, M+1), N)
    score = []
    for i in iters:
        stmp = 0
        for q in qlist:
            a = q[0]-1; b = q[1]-1
            if i[b] - i[a] == q[2]:
                stmp += q[3]
        score.append(stmp)
    
    ans = max(score)
    print(ans)


if __name__ == "__main__":
    main()


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

const int MAX = 1e5 + 10;

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

	int c[MAX]={0};

	for(int i=0;i<m;i++)
	{
		int a,b; cin>>a>>b;
		c[a]++; c[b]++;
	}

	for(int i=1;i<=n;i++){
		if(c[i]%2==1){
			cout<<"NO"; return 0;
		}
	}

	cout<<"YES";
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        // 入力データの取得
        Scanner scanner = new Scanner(System.in);
        String inputData = scanner.nextLine();
        scanner.close();

        // 入力データの加工
        long editedInputData = Long.parseLong(inputData);

        // 攻撃の処理
        // モンスターの体力が1のときとそれ以外で分岐する
        long totalAttack = 0;
        if (editedInputData == 1) {
            totalAttack = 1;
        } else {
            double count = 0;
            while (true) {
                count++;
                editedInputData /= 2;
                if (editedInputData == 1) {
                    break;
                }
            }
            for (int index = 0; index <= count; index++) {
                totalAttack += (long) (Math.pow(2, index));
            }
        }

        // 判定結果を出力する
        System.out.println(totalAttack);

    }

}

Measured memory_bytes: 25044
//void _(){
//    ll s;
//    cin >> s;
//    ll x = sqrt(s)-100;
//    x = max(x,0ll);
//    while((x+1)*(x+1) <= s)
//        ++x;
//    ll x1 = x;
//    ll y2 = x;
//    while(x1*y2 < s){
//        if(x1 < y2)
//            x1++;
//        else
//            y2++;
//    }
//    ll rem = x1*y2-s;
//    assert(rem >= 0);
//    assert(rem <= 1000000000);
//    ll x2 = rem;
//    ll y1 = 1;
//    cout << 0 << ' ' << 0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
//}
//
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
void _(){
    ll s;
    cin >> s;
    ll x = sqrt(s)-100;
    x = max(x,0ll);
    while((x+1)*(x+1) <= s)
        ++x;
    ll x1 = x;
    ll y2 = x;
    while(x1*y2 < s){
        if(x1 < y2)
            x1++;
        else
            y2++;
    }
    ll rem = x1*y2-s;
    assert(rem >= 0);
    assert(rem <= 1000000000);
    ll x2 = rem;
    ll y1 = 1;
    cout << 0 << ' ' << 0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+') cout << a + b << endl;
  else cout << a - b << endl;
}
  

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <bits/stdc++.h>

using namespace std;

class DKi {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, q;
        cin >> n >> q;
        map<int, vector<int>> ab_map;
        for (int i = 0; i < n - 1; ++i) {
            int a, b;
            cin >> a >> b;
            ab_map[a].emplace_back(b);
            ab_map[b].emplace_back(a);
        }
        vector<int> px_vec(n + 1, 0);
        for (int j = 0; j < q; ++j) {
            int p, x;
            cin >> p >> x;
            px_vec[p] += x;
        }
        vector<bool> seen(n + 1, false);
        vector<int> next_candidates;
        next_candidates.emplace_back(1);

        while (!next_candidates.empty()) {
            int candidate = next_candidates.back();
            next_candidates.pop_back();
            seen[candidate] = true;
            for (auto item : ab_map[candidate]) {
                if (seen[item] == true) continue;
                next_candidates.emplace_back(item);
                px_vec[item] += px_vec[candidate];
            }
        }

        for (int k = 1; k < n + 1; ++k) {
            cout << px_vec[k] << " ";
        }
        cout << endl;
    }

};


int main() {
	DKi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 26612
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n;

struct Elem {
    string name;
    int idx;
};
vector< vector<Elem> > G;

void dfs(int p, int cnt=0) {
    //  printf("p = %lld\n", p);
    for(size_t i=0; i<G[p].size(); i++) {
        Elem to = G[p][i];
        for(int x=0; x<cnt; x++) printf(".");
        cout << to.name << endl;
        dfs(to.idx, cnt+1); 
    }
}

signed main() {
    cin >> n;
    G.resize(n+1);
    int k; string s;
    rep(i,0,n) {
        cin >> k >> s;
        G[k].push_back(Elem{s, i+1});
    }
    dfs(0);
    return 0;
}

Measured memory_bytes: 3388
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

ll read(){
  ll x=0,f=1;char c=getchar();
  while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
  while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
  return x*f;
}

const int mod = 1000003;
int A[1000100];

inline int ksm(int x, int p) {
	int ret = 1;
	while (p) {
		if (p & 1) ret = ret * 1ll * x % mod;
		p >>= 1; x = x * 1ll * x % mod;
	}
	return ret;
}

void work() {
	A[0] = 1;
	rep(i, 1, mod) A[i] = A[i - 1] * 1ll * i % mod;
	int tc = read();
	while (tc--) {
		int x = read(), d = read(), n = read();
		if (d == 0) {
			printf("%d\n", ksm(x, n));
			continue;
		}
		x = x * 1ll * ksm(d, mod - 2) % mod;
		int ans = ksm(d, n);
		if (x + n - 1 >= mod) {
			puts("0");
			continue;
		}
		ans = ans * 1ll * A[x + n - 1] % mod * ksm(A[x - 1], mod - 2) % mod;
		printf("%d\n", ans);
	}
}

int main() {
  #ifdef LZT
    freopen("in","r",stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 4736
import numpy as np

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

B_array = np.array(B)
A_array = np.array(A)

count = 0
for i in range(N):
    code = (A_array[i, :] * B_array).sum() + C

    if code > 0:
        count += 1

print(count)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, M; cin >> N >> M;
	vector<bitset<10>> flag(M);
	vint p(M);	
	for (int i = 0; i < M; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int s; cin >> s; --s;
			flag[i][s] = true;
		}
	}
	cin >> p;
	int ans = 0;
	for (int b = 0; b < (1<<N); b++) {
		vint cnt(M);
		for (int i = 0; i < N; i++) {
			if (((b>>i)&1)) {
				for (int j = 0; j < M; j++) {
					if (flag[j][i] == true) cnt[j]++;
				}
			}
		}
		bool flag = true;
		for (int i = 0; i < M; i++) {
			flag &= ((cnt[i]&1) == p[i]);
		}
		if (flag) ans++;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

 int main(void){
   int a,b;
   char op;
   while(1){
     cin>>a>>op>>b;
     if(op=='?')break;
     if(op=='+')cout<<a+b<<endl;
     else if(op=='-')cout<<a-b<<endl;
     else if(op=='*')cout<<a*b<<endl;
     else if(op=='/')cout<<a/b<<endl;
   }
 }


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        string n = cin.nextString();
        for (int i = 0; i < n.Length; i++)
        {
            if (n[i] == '1')
            {
                Console.Write('9');
            }
            else
            {
                Console.Write('1');
            }
        }
        Console.Write("\n");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 11092
n = int(input())

happiness = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0]*3 for _ in range(n)]

dp[0][0] = happiness[0][0]
dp[0][1] = happiness[0][1]
dp[0][2] = happiness[0][2]

for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + happiness[i][j])
print(max(dp[n-1]))


Measured memory_bytes: 74712
#include <stdio.h>
int main(void){    
int i, x, y;
for(i = 0; i < 3000; i++) {  
scanf("%d %d", &x,&y);  
if(x == 0 && y == 0) {    
break;  }  else if(x<y) { 
printf("%d %d\n", x,y);  }  
else { 
printf("%d %d\n", y,x);  

}}  
return 0;
    }


Measured memory_bytes: 2064
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		long h = sc.nextLong();
		long w = sc.nextLong();
		
		long x = (-1000)*(h*w-1)-1;
		String[] ans = new String[H];
		for(int i=0; i<H; ++i){
			ans[i] = "";
		}
		
		long sum = 0;
		for(int i=1; i<=H; ++i){
			StringBuilder sb = new StringBuilder();
			for(int j=1; j<=W; j++){
				if(i%h==0 &&j%w==0){
					sb.append(x);
					sb.append(" ");
					sum+=x;
				}else{
					sb.append(1000);
					sb.append(" ");
					sum+=1000;
				}
			}
			sb.deleteCharAt(sb.length()-1);	
			ans[i-1] = sb.toString();
		}
		
		if(sum<=0) System.out.println("No");
		else{
			System.out.println("Yes");
			for(int i=0; i<H; i++){
				System.out.println(ans[i]);
			}
		}
		return;
	}
}

Measured memory_bytes: 39512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

string app() {
  int n;
  cin>>n;

  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }

  // ふるい
  int MAX=1e6+10;
  vector<int> divisors(MAX);
  rep(i,MAX) divisors[i]=i;
  rep_range(i,2,1e3+1){
    int j=0;
    while((j+=i)<MAX) {
      if(divisors[j]==j) divisors[j]=i;
    }
  }

  set<int> any,all;
  int t=a[0];
  while(t>1){
    all.emplace(divisors[t]);
    t/=divisors[t];
  }

  bool anyfailed=false;
  rep(i,n){
    auto itall=all.begin();
    int t=a[i];
    int lastu=0;
    while(t>1){
      int u=divisors[t];
      if(u!=lastu){
        if(any.count(u)>0) anyfailed=true;
        any.emplace(u);
        while(itall!=all.end()&&*itall<u) itall=all.erase(itall);
        if(itall!=all.end()&&*itall==u) itall++;
      }
      t/=divisors[t];
      lastu=u;
    }
    while(itall!=all.end()) itall=all.erase(itall);
  }

  if(anyfailed==false) return "pairwise coprime";
  if(all.empty()) return "setwise coprime";
  return "not coprime";
}

int main(){cout<<app()<<endl;return 0;}


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

#define ll long long
#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll mar = (N + 1) * (N + 2) / 2;
    ll sum = 0;
    ll m  = 1e9+7;
    for(ll i = K;i <= N + 1;i++) {
        ll t = N - i + 1;
        ll mi = i * (i + 1) / 2;
        ll ma = mar - t * (t + 1) / 2;
        sum += ma - mi + 1;
        sum %= m;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3632
# encoding: utf-8


import sys
import math

_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)


class Point(object):
    def __init__(self, x=0.0, y=0.0):
        """
        initialize the point
        """
        self.x = float(x)
        self.y = float(y)


def koch_curve(d, p1, p2):
    if not d:
        # print('end')
        return None

    # s, t, u = Point(), Point, Point()
    s = Point()
    t = Point()
    u = Point()
    s.x = (2 * p1.x + p2.x) / 3
    s.y = (2 * p1.y + p2.y) / 3

    t.x = (p1.x + 2 * p2.x) / 3
    t.y = (p1.y + 2 * p2.y) / 3

    u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
    u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y

    koch_curve(d - 1, p1, s)
    print(format(s.x, '.8f'), format(s.y, '.8f'))

    koch_curve(d - 1, s, u)
    print(format(u.x, '.8f'), format(u.y, '.8f'))

    koch_curve(d - 1, u, t)
    print(format(t.x, '.8f'), format(t.y, '.8f'))

    koch_curve(d - 1, t, p2)


if __name__ == '__main__':
    p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
    print(format(p1_start.x, '.8f'), '', format(p1_start.y, '.8f'))
    koch_curve(depth, p1_start, p2_end)
    print(format(p2_end.x, '.8f'), '', format(p2_end.y, '.8f'))

Measured memory_bytes: 8096
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int64_t sum1=0,sum2=0,cnt=0;
  for(int i=0;i<n;i++){
    if(s[i]=='B'){cnt++;sum2+=i;}
  }
  for(int i=n-cnt;i<n;i++){
    sum1+=i;
  }
  cout<<sum1-sum2<<endl;

  return 0;
}

Measured memory_bytes: 640