akhauriyash/Code-Regression huggingface dataset:
N = int(input())
Points = [[i] + list(map(int, input().split())) for i in range(N)]

# x, yそれぞれについてソートして、一番近いところを見れば十分
Edges = []
Points.sort(key=lambda p: p[1])
for i in range(N - 1):
    n1, x1, y1 = Points[i]
    n2, x2, y2 = Points[i + 1]
    Edges.append([n1, n2, x2 - x1])

Points.sort(key=lambda p: p[2])
for i in range(N - 1):
    n1, x1, y1 = Points[i]
    n2, x2, y2 = Points[i + 1]
    Edges.append([n1, n2, y2 - y1])


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uf = UnionFind(N)
Edges.sort(key=lambda e: e[2], reverse=True)
MST_cost = 0
i = 0

# 辺のコストが小さいものから、閉路を作らないように、木を構成する
# 最小全域木の必要辺は(頂点数-1)本
while i != N - 1:
    x, y, cost = Edges.pop()
    # 同じ辺集合に属していないならば（閉路が生まれないならば）
    if not uf.same_check(x, y):
        MST_cost += cost
        uf.union(x, y)
        i += 1

print(MST_cost)


Measured memory_bytes: 59316
mod = 1000000007
s = input()
n = len(s)
c = [0 for i in range(n)] #c[i]=(s[i:]に存在する'C'の個数)
d = [0 for i in range(n)] #d[i]=(s[i:]に存在する'?'の個数) これ以降も、変数名に現れる'd'は'?'に対応する
bc = [0 for i in range(n)] #bc[i]=(s[i:]に存在する"BC"の個数)
bd = [0 for i in range(n)] #上と同様、"B?"
dc = [0 for i in range(n)] #"?C"
dd = [0 for i in range(n)] #"??"


if s[-1] == "C":
    c[-1] = 1
if s[-1] == "?":
    d[-1] = 1
for i in range(-2, -n-1, -1): #後ろから2文字目～先頭を見る
    c[i] = c[i+1]
    d[i] = d[i+1]
    bc[i] = bc[i+1]
    bd[i] = bd[i+1]
    dc[i] = dc[i+1]
    dd[i] = dd[i+1]
    if s[i] == "B":
        bc[i] += c[i+1] #今見つけた'B'と、今までに見つけた'C'で"BC"をつくる。後に続くのも同様。
        bd[i] += d[i+1]
    elif s[i] == "C":
        c[i] += 1
    elif s[i] == "?":
        d[i] += 1
        dc[i] += c[i+1]
        dd[i] += d[i+1]

# d[0]は'?'の総数で、問題文中のQに対応する
if d[0] == 0: #d[0]が3に満たないときはバグるので別扱い
    mul = [0, 0, 0, 1]
elif d[0] == 1:
    mul = [0, 0, 1, 3]
elif d[0] == 2:
    mul = [0, 1, 3, 9]
else:
    mul = [1, 1, 1, 1] #以下の処理でmul=[3**(Q-3),3**(Q-2),3**(Q-1),3**Q]となる
    for i in range(d[0]-3): #3をQ-3乗
        mul[0] *= 3
        mul[0] %= mod
    for i in range(3): #あとは順に3倍
        mul[i+1] = (mul[i]*3) % mod

res = 0
for i in range(n-2): #一文字ずつ見ていって足し上げる
    if s[i] == "A":
        res += bc[i+1]*mul[3]+(dc[i+1]+bd[i+1])*mul[2]+dd[i+1]*mul[1]
    if s[i] == "?":
        res += bc[i+1]*mul[2]+(dc[i+1]+bd[i+1])*mul[1]+dd[i+1]*mul[0]
    res %= 1000000007
print(res)


Measured memory_bytes: 50552
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i = 0; i <= N-3; i++){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();

        char[] data = S.toCharArray();
        int len = data.length;
        if (!is_kaibun(S, 1, len)) {
            System.out.println("No");
            return;
        }
        if (!is_kaibun(S, 1, (len-1)/2)) {
            System.out.println("No");
            return;
        }
        if (!is_kaibun(S, (len+3)/2, len)) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }

    private boolean is_kaibun(String S, int start, int end) {
        String org = S.substring(start-1, end);
        StringBuilder sb = new StringBuilder(org);
        String tran = sb.reverse().toString();
        return org.equals(tran);
    }
}


Measured memory_bytes: 23252
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
s = gets.chomp
t = 0
l = 0
r = 0
s.each_char do |c|
  if(c =="(")
    t += 1 
  else
    t -= 1
  end
  if(t<0)
    t += 1
    l += 1
  end
end
s = "("*l+s+")"*t
puts s


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    int A, B;
    cin >> A >> B;

    int ans = 0;
    int sum = 1;

    while(sum < B){

        sum = sum - 1 + A;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
typedef long long LL;
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy";
    }else if(s=="Cloudy"){
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }
    cout << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   998244353 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
   int x , y , a , b , c ;
   cin >> x >> y >> a >> b >> c ;
   vector < ll > red(a) , green(b) , col(c);
   for( int i = 0 ; i < a ; i++) cin >> red[i] ;
   for( int i = 0 ; i < b ; i++) cin >> green[i] ;
   for( int i = 0 ; i < c ; i++) cin >> col[i] ;
   sort(red.rbegin(),red.rend());
   sort(green.rbegin(),green.rend());
   vector < pair < ll , int > > ans ;
   for( int i = 0 ; i < x ; i++) ans.push_back({red[i],0});
   for( int j = 0 ; j < y ; j++) ans.push_back({green[j],1});
   for( int k = 0 ; k < c ; k++) ans.push_back({col[k],2});
   sort(ans.rbegin(),ans.rend());
   int p = x , q = y ;
   int cnt = 0 ;
   ll sum = 0 ;
   for( int i = 0 ; i < x+y ; i++){
        if(p>0 && ans[i].ss==0){
            sum += ans[i].ff;
            p--;
        }
        if(q>0 && ans[i].ss==1){
            sum += ans[i].ff;
            q--;
        }
        if(ans[i].ss==2){
            sum += ans[i].ff ;
            cnt++;
        }
   }
  // cout << sum << " " ;
   int req = p+q-cnt ;
   for( int i = x+y ; i <=req ; i++){
        sum += ans[i].ff ;
   }
   cout << sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t ;
    t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}
// number of subset having xor in 2ki ow


Measured memory_bytes: 12908
# C - たくさんの数式 / Many Formulas
s = input()
d = []
ans = 0
for i in range(2 ** (len(s) - 1)):
    tmp = s[0]
    for j in range(len(s) - 1):
        # print("     i :", i)
        # print("1 << j :", 1 << j)
        # print("  1tmp :", tmp)
        if i & (1 << j):
            tmp += "+"
        tmp += s[j+1]
        # print("  2tmp :", tmp)
        d.append(tmp)
    ans += eval(tmp)

# print(d)
print(ans)


Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace problem001
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var s = Console.ReadLine().Split(' ');
			StringBuilder builder = new StringBuilder();
			for(int i = 0; i < n; i++)
			{
				builder.Append(s[0][i]);
				builder.Append(s[1][i]);
			}
			Console.WriteLine(builder.ToString());
		}
	}
}


Measured memory_bytes: 13140
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define MX 100005

using namespace std;

typedef long long ll;

template <typename T> void read(T& x)
{
	bool f = 0; x = 0; char c = getchar();
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll seq[MX], len;
ll mul[MX], add[MX];
ll n, q;

int main()
{
	ll a;
	read(n); read(q);
	seq[++len] = n;
	for(int i=1; i<=q; i++)
	{
		read(a);
		while(len && a<=seq[len]) len--;
		seq[++len] = a;
	}
	mul[len] = 1;
	for(int i=len; i>=2; i--)
	{
		ll rem = seq[i] % seq[i-1];
		mul[i-1] += mul[i] * (seq[i] / seq[i-1]);
		while(1)
		{
			int p = upper_bound(seq+1, seq+len+1, rem) - seq - 1;
			if(p == 0) {add[rem] += mul[i]; break;}
			else mul[p] += (rem / seq[p]) * mul[i], rem %= seq[p];
		}
	}
	add[seq[1]] += mul[1];
	for(int i=n; i>=1; i--) add[i] += add[i+1];
	for(int i=1; i<=n; i++) printf("%lld\n", add[i]);
	return 0;
}

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

int main() {
    string ABC;
    ABC = "abcdefghijklmnopqrstuvwxyz";
    char C;
    cin >> C;
    for (int i=0; i<25; i++){
        if (C == ABC.at(i)){
            cout << ABC.at(i+1) <<endl;
        }
    }
}


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

int main(void){

    int N,M;
    cin>>N>>M;

    vector<int> dp(N+1, true);
    int tmp;
    for (int i = 0; i < M; ++i) {
        cin>>tmp;
        dp[tmp] = false;
    }

    for (int i = 2; i <= N; ++i) {
        if(dp[i] == false) continue;
        dp[i] = dp[i-1]+dp[i-2];
        dp[i] %= 1000000007;
    }

    cout <<dp[N]<<endl;

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
def solve(n, m, a):
    odd = []
    even = []
    for a_i in a:
        if a_i % 2 == 0:
            even += [ a_i ]
        else:
            odd += [ a_i ]
    if len(odd) >= 3:
        return None
    a, b = [], []
    if odd:
        x = odd.pop()
        a += [ x ]
        b += [ x - 1 ]
    else:
        x = even.pop()
        a += [ x ]
        b += [ x - 1 ]
    a += even
    b += even
    if odd:
        x = odd.pop()
        a += [ x ]
        b += [ x + 1 ]
    else:
        b += [ 1 ]
    return a, b

n, m = map(int, input().split())
a = list(map(int, input().split()))
it = solve(n, m, a)
if it is None:
    print('Impossible')
else:
    a, b = it
    b = list(filter(lambda b_i: b_i, b))
    print(*a)
    print(len(b))
    print(*b)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n, m;

int main(){
    scanf("%d", &n);
    int a = n / 3600;
    n -= a*3600;
    printf("%d:", a);

    int b = n / 60;
    n -= b*60;
    printf("%d:", b);

    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 3240
#include<iostream>
using namespace std;
int main (){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if(x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H)
  cout << "Yes\n";
  else cout << "No\n";
  return 0;
  
}

Measured memory_bytes: 1124
#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 <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = 0;
    REP(i, 101){
        if (a <= i && i < b && c <= i && i < d) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF){
    if(a>b)
        printf("a > b\n");
    if(a<b)
        printf("a < b\n");
    if(a==b)
        printf("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2040
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;
	vector<int> a(m);

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

	sort(a.rbegin(), a.rend());


	vector<int> num = {-1,2,5,5,4,5,6,3,7,6 };
	vector<int> digit(n+1,-1000000);

	digit[0] = 0;

	for (int i = 1; i < n+1; i++) {

		for (int j = 0; j < m; j++) {

			int from = i - num[a[j]];
			if (from< 0)continue;

			digit[i] = max(digit[i], digit[from]+1);
		}
		
	}

	while (n > 0) {
		for (int i = 0; i < m; i++) {
			if (n - num[a[i]] < 0)continue;

			if (digit[n-num[a[i]]]==(digit[n]-1)) {
				cout << a[i];
				n -= num[a[i]];
				break;
			}
		}
	}
	
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    int ans = 0, mn = a[0];
    rep(i, 0, n) {
        if (mn < a[i]) {
            mn = a[i];
        } else {
            ans += mn - a[i];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5156
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in); 

        int n = sc.nextInt();
        int[] v = new int[n];
        for(int i = 0; i < n; i++){
            v[i] = sc.nextInt();
        }
        sc.close();
        int[] even = new int[100001];
        int[] odd = new int[100001];
        for(int i = 0; i < n; i=i+2){
            even[v[i]]++;
            odd[v[i+1]]++;
        }
        if(max_index(even) != max_index(odd)){
            System.out.println((n/2 - even[max_index(even)]) + (n/2 - odd[max_index(odd)]));
        } else{
            if((n/2 - even[max_index(even)]) + (n/2 - second(odd)) > (n/2 - second(even)) + (n/2 - odd[max_index(odd)])){
                System.out.println((n/2 - second(even)) + (n/2 - odd[max_index(odd)]));
            } else{
                System.out.println((n/2 - even[max_index(even)]) + (n/2 - second(odd)));
            }
        }
       
    }
    static int max_index(int[] a){
        int index = 0;
        int max = a[0];
        for(int i = 1; i < a.length; i++){
            if(a[i] > max){
                max = a[i];
                index = i;
            }
        }
        return index;
    }
    
    static int second(int[] a){
        int max1 = 0;
        int max2 = 0;
        for(int i = 0; i < a.length; i++){
            if(a[i] > max1){
                max2 = max1;
                max1 = a[i];
            }else if(a[i] > max2){
                max2 = a[i];
            }
        }
        return max2;
    }
}

Measured memory_bytes: 52096
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll k=in();
    ll ans=0;
    for(int i=1;i<=k;++i)for(int j=1;j<=k;++j)for(int l=1;l<=k;++l)ans+=gcd(gcd(i,j),l);
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        auto it = mp.upper_bound(-a[i]);

        if (it != mp.end())
        {
            it->second -= 1;
            if (it->second == 0)
                mp.erase(it);
        }
        mp[-a[i]]++;

    }
    int res = 0;
    for (auto it : mp)
        res += it.second;
    cout << res << "\n";
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    int left[n + 1];
    int right[n + 1];
    rep(i, n)
    {
        cin >> s[i];
        sum += s[i];
    }
    sort(s.begin(),s.end());
    if(sum%10!=0){
        cout << sum << endl;
        return 0;
    }
    rep(i,n){
        if(s[i]%10!=0){
            cout << sum-s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()
l = len(s)-1
ans = 0
ops = []

# +あり/なしの全探索のため、桁数-1の2乗
for i in range(2**l):
    op = [""] * l
    for j in range(l):
        if ((i >> j) & 1) == 1:
            op[l-1-j] = "+"
    ops.append(op)

for o in ops:
    str = [str for str in s]
    for k in range(len(o)):
        str.insert(2*k+1, o[k])
    ans += eval(''.join(str))

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
#define MOD 1000000007
#define MAX_N 100000
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P];
Int extgcd(Int a,Int b,Int& x,Int& y){
  Int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}
Int euler_phi(Int n){
  Int res=n;
  for(Int i=2;i*i<=n;i++){
    if(n%i==0){
      res=res/i*(i-1);
      for(;n%i==0;n/=i);
    }
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}

Int euler[MAX_N];

void euler_phi2(){
  for(Int i=0;i<MAX_N;i++) euler[i]=i;
  for(Int i=2;i<MAX_N;i++){
    if(euler[i]==i){
      for(Int j=i;j<MAX_N;j+=i) euler[j]=euler[j]/i*(i-1);
    }
  }
}

Int mod_pow(Int x,Int n,Int mod){
  Int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

Int mod_inverse2(Int a,Int mod){
  return mod_pow(a,mod-2,mod);
}

void init(Int mod){
  fact[0]=1;
  for(Int i=1;i<MAX_P;i++)
    fact[i]=(fact[i-1]*i)%mod;

  inv[1]=1;
  for(Int i=2;i<MAX_P;i++)
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
}

Int mod_fact(Int n,Int mod,Int& e){
  e=0;
  if(n==0) return 1;
  Int res=mod_fact(n/mod,mod,e);
  e+=n/mod;
  if(n/mod%2!=0)return res*(mod-fact[n%mod]) %mod;
  return res*fact[n%mod]%mod;
}

Int mod_comb(Int n,Int k,Int mod){
  if(n==k||k==0) return 1;
  Int e1,e2,e3;
  Int a1=mod_fact(n,mod,e1),a2=mod_fact(k,mod,e2),a3=mod_fact(n-k,mod,e3);
  if(e1>e2+e3) return 0;
  return a1*mod_inverse(a2*a3%mod,mod)%mod;
}

Int mod_comb2(Int n,Int k,Int mod){
  Int res=1;
  for(Int i=0;i<k;i++){
    res*=(n-i)%mod;
    res%=mod;
    res*=mod_inverse(i+1,mod);
    res%=mod;
  }
  return res;
}

Int montmort(Int n,Int mod){
  Int res=0,inv=1;
  for(Int k=2;k<=n;k++){
    (inv*=mod_inverse(k,mod))%=mod;
    if(k%2) (res+=mod-inv)%=mod;
    else (res+=inv)%=mod;
  }
  for(Int i=1;i<=n;i++)
    (res*=i)%=mod;
  return res;
}
//END CUT HERE

//mod_pow
signed AOJ_NTL1B(){
  int n,m;
  cin>>m>>n;
  cout<<mod_pow(m,n,MOD)<<endl;
  return 0;
}
/*
  verified on 2017/12/31
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B&lang=jp
*/


//euler_phi:
signed AOJ_NTL1D(){
  int n;
  cin>>n;
  cout<<euler_phi(n)<<endl;
  return 0;
}
/*
  verified on 2017/12/31
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_D&lang=jp
*/

//montmort
signed ARC009_C(){
  Int n,k;
  cin>>n>>k;
  const Int MMOD=1777777777;
  Int a=montmort(k,MMOD);
  a=a*mod_comb2(n,k,MMOD)%MMOD;
  cout<<a<<endl;
  return 0;
}
/*
  verified on 2017/12/31
  https://arc009.contest.atcoder.jp/tasks/arc009_3
*/


signed main(){
  //AOJ_NTL1B();
  AOJ_NTL1D();
  
  //ARC009_C();
  return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;
//無様なコード　2番めに多いものを探す方法はもっといいものが有るはず
int main2(), main();
const int arrlen = 100001;


int main(){
    int i,j,k;
    string s;
    cin>>s;

    int len = s.length();
    string odd = "RUD", EVEN = "ULD";
    //cout << len << endl;
    
    bool found2 = true;
    rep(i,len){
        bool found = false;
        rep(j,3){
            if(i%2 == 0 && odd[j] == s[i]) found = true;
            if(i%2 == 1 && EVEN[j] == s[i]) found = true;
        }
        if(!found) found2 = false;
    }
    if(found2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


signed main() {
    ll h, w, m;
    cin >> h >> w >> m;
    map<pair<ll, ll>, bool> mp;
    vll r(h, 0);
    vll c(w, 0);
    
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        x--; y--;
        mp[{x, y}] = true;
        r[x]++;
        c[y]++;
    }
 
    ll maxR = 0;
    rep(i, h) {
        if (r[i] > maxR) maxR = r[i];
    }
    vll list1;
    rep(i, h) {
        if (r[i] == maxR) list1.pb(i);
    }
 
    ll maxC = 0;
    rep(i, w) {
        if (c[i] > maxC) maxC = c[i];
    }
    vll list2;
    rep(i, w) {
        if (c[i] == maxC) list2.pb(i);
    }
 
    ll ans = maxR + maxC;
    for (auto x : list1) {
        for (auto y : list2) {
            if (mp.count({x, y}) == 0) {
                mes(ans);
                re0;
            }
        }
    }
 
    mes(ans-1);
    
    
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	int a;
	string s;
	cin>>a>>s;
	if(a < 3200)cout << "red\n";
	else cout << s << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdinLock};
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let (h, w, d): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let mut a: Vec<Vec<_>> = vec![vec![0; w]; h];
    let mut pos: Vec<(i32, i32)> = vec![(0, 0); h * w + 1];
    for i in 0..h {
        for j in 0..w {
            a[i][j] = sc.read();
            pos[a[i][j]] = (i as i32, j as i32);
        }
    }

    let mut ans: Vec<_> = vec![0; h * w + 1];
    for i in 1..(h * w + 1 - d) {
        ans[i + d] = ans[i] + (pos[i + d].0 - pos[i].0).abs() + (pos[i + d].1 - pos[i].1).abs();
    }

    let q: usize = sc.read();
    for _ in 0..q {
        let (l, r): (usize, usize) = (sc.read(), sc.read());
        writeln!(out, "{}", ans[r] - ans[l]).unwrap();
    }
}

Measured memory_bytes: 7292
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
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 Graph = vector<vector<int>>;

typedef pair<int, int> P;


int main(){
    int N; cin >> N;
    vector<vector<int>> A(N,vector<int>(N-1));
    rep(i,N){
        rep(j,N-1){
            cin >> A[i][j];
            A[i][j]--;
        }

        // vectorは末尾の削除は早いが、先頭は遅いのでreverse
        reverse(A[i].begin(), A[i].end());
    }

    vector<pair<int,int>> q;
    // 試合を登録
    auto check = [&](int i){
        if (A[i].size() == 0) return;
        int j = A[i].back();
        if (A[j].size() == 0) return;
        if (A[j].back() == i){
            P p(i,j);
            if (p.second < p.first) swap(p.first, p.second);
            q.push_back(p);
        }
    };
    rep(i,N){
        check(i);
    }
    int day = 0;
    while (q.size() > 0){
        day++;
        // 重複を削除する前準備としてソートしておく。
        sort(q.begin(), q.end());
        // 重複を削除
        q.erase(unique(q.begin(),q.end()), q.end());
        vector<pair<int,int>> prevQ;
        
        // prevQにqを入れて, qを空にする。
        // vectorのswapは早い
        swap(prevQ, q);
        
        for (auto p : prevQ){
            int i = p.first, j = p.second;
            // 試合を行う。
            // pop_back()は末尾の要素の削除
            A[i].pop_back();
            A[j].pop_back();
        }
        // 翌日の試合を登録
        for (auto p : prevQ){
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }

    rep(i,N){
        // 試合が残ってしまったら-1
        if (A[i].size() != 0){
            puts("-1");
            return 0;
        }
    }

    cout << day << endl;

} 

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

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

using namespace std;

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

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int k, a, b;
  cin >> k >> a >> b;
  if (b - a <= 2) {
    cout << k + 1 << endl;
    return;
  }
  int c = a - 1;
  if (c > k) {
    cout << k + 1 << endl;
    return;
  }
  i64 sum = a;
  k -= c;
  if (k & 1) k--, sum++;
  sum += (i64) (b - a) * (k / 2);
  cout << sum << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    H.sort(reverse=True)
    if K >= N:
        print(0)
        exit()
    print(sum(H[K:]))


if __name__ == '__main__':
    main()


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

int main() {
	int N, W;
	static long long DP[110][100100] = {};
	static long long w[100100], v[100100];
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) DP[i][j] = DP[i - 1][j];
			else DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << DP[N][W];
}

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

using namespace std;

#define N 100000
int n, arr[N], x;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<int> vi;
    bool last = false;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (x == i) {
            if (last)
                vi[vi.size() - 1]++;
            else {
                last = true;
                vi.push_back(1);
            }
        } else
            last = false;
    }
    int ans = 0;
    for (size_t i = 0; i < vi.size(); i++)
        ans += (vi[i] + 1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<string> s(2);
    bool isRight = true;
    for(int i=0; i<n; ++i){
        for(int j=0; ; ++j){
            vector<string> t(2);
            if(isRight){
                t[0] = s[0] + ((j & 1) ? '#' : '.');
                t[1] = s[1] + ((j & 2) ? '#' : '.');
            }
            else{
                t[0] = ((j & 1) ? '#' : '.') + s[0];
                t[1] = ((j & 2) ? '#' : '.') + s[1];
            }

            cout << t[0] << endl << t[1] << endl;
            string input;
            cin >> input;
            if(input == "T" || input == "end"){
                s = t;
                break;
            }
            if(j == 3)
                isRight = false;
        }
    }

    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int main() {
    map<char, int> map[60];
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (char ch : s) {
            map[i][ch]++;
        }
    }

    string ans = "";
    for (char ch = 'a'; ch <= 'z'; ch++) {
        int cnt = 1000000;
        for (int i = 0; i < n; i++) {
            cnt = min(cnt, map[i][ch]);
        }
        for (int i = 0; i < cnt; i++) {
            ans.push_back(ch);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// AOJ 2578 Disciple Life is Hard
// 2018.3.16 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// library //
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

// library //

int e[102], c[102], h[102], a[102];
int p[102];
int dp1[102][102*102], dp2[102][102][102], dp3[102][102];
int ee[102];
int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int S, T, U, N, O, D, i, j, s, x;

	S = in(), T = in(), U = in(), N = in(), O = in(), D = in();
	for (i = 0; i < T; i++) ee[i] = e[i] = in(), c[i] = in();
	for (i = 0; i < N; i++) h[i] = in(), a[i] = in();

	qsort(ee, T, sizeof(int), cmp);
	s = 0; for (i = 0; i < U; i++) s += ee[i];
	if (s > S || S-(D-1)*(s-O) < s) { puts("-1"); return 0; }

	memset(dp1, -1, sizeof(dp1)), dp1[0][0] = 0;
	for (i = 1; i <= N; i++) for (j = 0; j <= 10000; j++) for (s = 0; s*a[i-1] <= j; s++) {
		if (dp1[i-1][j-s*a[i-1]] >= 0) {
			x = dp1[i-1][j-s*a[i-1]]+h[i-1]*s;
			if (dp1[i][j] < x) dp1[i][j] = x;
		}
	}

	memset(dp2, -1, sizeof(dp2)); dp2[0][0][0] = 0;
	for (i = 1; i <= T; i++) {
		dp2[i][0][0] = 0;
		for (j = 1; j <= i; j++) for (s = 0; s <= S; s++) {
			dp2[i][j][s] = dp2[i-1][j][s];
			if (s-e[i-1] >= 0 && dp2[i-1][j-1][s-e[i-1]] >= 0) {
				x = dp2[i-1][j-1][s-e[i-1]]+c[i-1];
				if (dp2[i][j][s] < x) dp2[i][j][s] = x;
			}
		}
	}

	memset(p, -1, sizeof(p));
    for (s = 0; s <= S; s++) for (i = 0; i <= dp2[T][U][s]; i++) if (p[s] < dp1[N][i]) p[s] = dp1[N][i];

	memset(dp3, -1, sizeof(dp3)), memset(dp3[0], 0, sizeof(dp3[0]));
	for (i = 1; i <= D; i++) for (s = 0; s <= S; s++) for (j = 0; j <= s; j++) {
		x = s-j+O; if (x > S) x = S;
		if (dp3[i-1][x] >= 0 && p[j] >= 0) {
			int t = dp3[i-1][x] + p[j];
			if (dp3[i][s] < t) dp3[i][s] = t;
		}
	}
	printf("%d\n", dp3[D][S]);
}


Measured memory_bytes: 10072
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
char mp[2005][2005];
int mp_zong[2005][2005];
int mp_heng[2005][2005];
int n, m;
int maxx = 0;
int main()
{
    ll maxx_ans = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> mp[i] + 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (mp[i][j] == '.')
            {
                if (mp_zong[i][j] == 0)
                {
                    int num = 0;
                    int minn = 1, maxx = n;
                    for (int k = i; k <= n; k++)
                        if (mp[k][j] == '#')
                        {
                            maxx = k - 1;
                            break;
                        }
                        else
                            num++;
                    for (int k = i - 1; k >= 1; k--)
                        if (mp[k][j] == '#')
                        {
                            minn = k + 1;
                            break;
                        }
                        else
                            num++;
                    for (int l = minn; l <= maxx; l++)
                        mp_zong[l][j] = num;
                }
                if (mp_heng[i][j] == 0)
                {
                    int num = 0;
                    int minn = 1, maxx = m;
                    for (int k = j; k <= m; k++)
                        if (mp[i][k] == '#')
                        {
                            maxx = k - 1;
                            break;
                        }
                        else
                            num++;
                    for (int k = j - 1; k >= 1; k--)
                        if (mp[i][k] == '#')
                        {
                            minn = k + 1;
                            break;
                        }
                        else
                            num++;
                    for (int l = minn; l <= maxx; l++)
                        mp_heng[i][l] = num;
                }
                // printf("%d %d %d %d   %d\n", i, j, mp_heng[i][j], mp_zong[i][j], mp_heng[i][j] + mp_zong[i][j] - 1);
                if (mp_heng[i][j] + mp_zong[i][j] - 1 > maxx_ans)
                    maxx_ans = mp_heng[i][j] + mp_zong[i][j] - 1;
            }
    cout << maxx_ans << endl;

    return 0;
}


Measured memory_bytes: 35584
import math
a, b , n = map(int, input().split())

s1 = math.floor(a * n / b) - a * math.floor(n / b)
if n < b:
    print(s1)
    exit()

ans = 0
for i in range(b, b - 10*3, -1):
    ans = max(math.floor(a * (b-1) / b) - a * math.floor((b-1) / b), ans)
print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int H, W;
    std::cin >> H >> W;

    char C[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            std::cin >> C[i][j];
        }
    }

    char ans[2*H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (C[i][j] == '*') {
                ans[2*i][j]   = '*';
                ans[2*i+1][j] = '*';
            } else if (C[i][j] == '.') {
                ans[2*i][j]   = '.'; 
                ans[2*i+1][j] = '.'; 
            }
        }
    }

    for (int i = 0; i < 2*H; i++) {
        for (int j = 0; j < W; j++) {
            std::cout << ans[i][j];
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long
/* define/include */

signed main(){
  int c[10][10]={};// i => j
  int m[10][10][10];// iについて i => j のコスト
  int H,W;
  LOOP(i,10){
    LOOP(j,10){
      LOOP(k,10){
        m[i][j][k]=INF;
      }
    }
  }
  cin >> H >> W;
  LOOP(i,10){
    LOOP(j,10){
      cin >> c[i][j];
      LOOP(k,10){
        m[k][i][j]=c[i][j];
      }
    }
  }
  LOOP(i,10){
    // cout << endl << endl << i << endl << endl << endl;
    LOOP(t,10){
      // cout << endl << "t" << t << endl << endl;
      LOOP(j,10){
        LOOP(k,10){
          LOOP(l,10){
            // cout << j << "-" << k << ":" <<  m[i][j][k] << " " << m[i][i][k]+m[i][k][j] << endl;
            m[i][j][k]=min(m[i][j][k],m[i][j][l]+m[i][l][k]);
          }
        }
      }
    }
  }
  int p;
  int t=0;
  LOOP(i,H){
    LOOP(j,W){
      cin >> p;
      if(p!=-1)
      t+=m[p][p][1];
    }
  }
  cout << t << endl;
}


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

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

  int m = n;
  int s = 0;
  while (m) {
    s += m % 10;
    m = m / 10;
  }
  if (n % s == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 const int AMAX = 100000;
 long long cnt[AMAX + 1];

int main(void) {
 int N;
 long long K;
 cin >> N >> K;

 for (int i = 0; i < N; ++i) {
 int A, B;
 cin >> A >> B;
 cnt[A] += B;
 }

 for (int ans = 1; ans <= AMAX; ++ans){
 if (K <= cnt[ans]) {
 cout << ans << endl;
 break;
 }
 K -= cnt[ans];
 }

 return 0;
 }

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Collections
{
	class program
	{
		static void Main(string[] args)
		{
			// 入力
			int N = Int32.Parse(Console.ReadLine());
			//string[] input = Console.ReadLine().Split(' ');
			int[] a = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();

			// 大きい方からボールを入れるかどうか決めていく
			int[] box = new int[N+1];
      int num = 0;
			StringBuilder sb = new StringBuilder();
			for(int i=N; i>0; i--)
			{
				// iの倍数の数が1個の場合、input[i-1]が0→入れない 1→入れる
				//Console.WriteLine(i + " " + N/i);
				if(N/i == 1)
				{
					if(a[i-1] == 1)
          {
            	box[i] = 1;
              sb.Append(i+ " ");
              num++;
          }

				}
				else
				{
					// iの倍数の数が2個以上の場合、iの倍数の箱に入っているボールの個数を数える...
					int ball = 0;
					for(int j=i, k=2; j<=N; j = i*k, k++)
					{
						//Console.WriteLine(i + "check " + j + " is " + box[j] );
						ball += box[j];
					}
					if(a[i-1] != ball%2)
          {
            box[i] = 1;
            sb.Append(i+ " ");
            num++;
          }

				}
			}

			Console.WriteLine(num + "");
			if(num > 0)
			{
				Console.WriteLine(sb.ToString());
			}
    }
	}
}


Measured memory_bytes: 32080
#include<stdio.h>
int main(){
	int a,b,c,d;
	char A;
	while(A!='\n'){
		scanf("%c",&A);
		if(islower(A))
			A=toupper(A);
			else if(isupper(A))
		A=tolower(A);
			
			printf("%c",A);
	}
	return 0;
}

Measured memory_bytes: 524
type Number = i64;

const M : Number = 1_000_000_007;

fn main()
{
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();

    let data: Vec<&str> = line.split_whitespace().collect();
    let r1 = data[0].parse().unwrap_or(0);
    let c1 = data[1].parse().unwrap_or(0);
    let r2 = data[2].parse().unwrap_or(0);
    let c2 = data[3].parse().unwrap_or(0);

    let n = r2 + c2 + 2;

    let mut facts : Vec<Number> = vec![1; n];
    let mut finvs : Vec<Number> = vec![1; n];
    let mut invs  : Vec<Number> = vec![1; n];

    invs[0] = 0;

    for i in 2..n
    {
        facts[i] = ((i as Number) * facts[i - 1]) % M;
        invs[i]  = M - (invs[(M as usize) % i] * (M / (i as Number))) % M;
        finvs[i] = (finvs[i - 1] * invs[i]) % M;
    }

    let ncr = |n: usize, r: usize| -> Number
    {
        (facts[n] * ((finvs[r] * finvs[n - r]) % M)) % M
    };

    let sum = |x: usize, y: usize| -> Number
    {
        (1 .. (x + 2)).fold(0, |val, index| (val + ncr(y + index, index)) % M)
    };

    let a = sum(r2, c2);
    let b = sum(r1 - 1, c2);
    let c = sum(r2, c1 - 1);
    let d = sum(r1 - 1, c1 - 1);

    let ans = (a + d - b - c + 4 * M) % M;
    println!("{}", ans);
}


Measured memory_bytes: 53500