akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  string t="";
  for(int i=0;i<s.size();i++){
    if(s[i]!='x'){
      t+=s.substr(i,1);
    }
  }
  for(int i=0;i<t.size()/2;i++){
    if(t[i]!=t[t.size()-1-i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  int ans=0;
  vector<int> v,w;
  int sum=0;
  int now=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='x')sum++;
    else{
      v.push_back(sum);
      sum=0;
      now++;
    }
    if(now==(t.size()+1)/2)break;
  }
  now=0;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='x')sum++;
    else{
      w.push_back(sum);
      sum=0;
      now++;
    }
    if(now==(t.size()+1)/2)break;
  }
  
  for(int i=0;i<v.size();i++){
    ans+=abs(v[i]-w[i]);
  }
  cout<<ans<<endl;
}

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

const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 int a,b,k;
 cin>>a>>b>>k;
 if(a+k-1>=b-k+1){
     for(int i=a;i<=b;i++)cout<<i<<endl;
 }else {
     for(int i=0;i<k;i++)cout<<a+i<<endl;
     for(int i=0;i<k;i++)cout<<b-k+1+i<<endl;
 }

return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int m,n,a[100][100],b[100];
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	for(int i=0;i<m;i++)
		cin>>b[i];
	int s;
	for(int i=0;i<n;i++)  {
		 s=0;
		for(int j=0;j<m;j++)
		{
		  s+=a[i][j]*b[j];
		}				   
		cout <<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3136
Ss = input()

isMM1 = '01' <= Ss[:2] <= '12'
isMM2 = '01' <= Ss[2:] <= '12'

if isMM1:
    if isMM2:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if isMM2:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
N = int(input())
A = [[0] * (N-1)]+[list(map(int,input().split())) for _ in range(N)]

idx = [0] * (N+1)
cnt = 0
day = 0
flag_max = [False] * (N+1)
while cnt != N:
    
    error = True
    flag =[False] * (N+1)
    looplist = [i for i in range(1,N+1) if not(flag_max[i])]
    
    for i in looplist:
        if (flag[i]):continue
        tmp = A[i][idx[i]]
        if (flag[tmp]):continue
    
        if A[tmp][idx[tmp]] == i:
            idx[tmp] = idx[tmp] + 1
            idx[i] = idx[i] + 1
            if idx[tmp] == N-1:
                flag_max[tmp] = True
                cnt += 1
            if idx[i] == N-1:
                flag_max[i] = True
                cnt += 1
            flag[i] = True
            flag[tmp] = True
            error = False
    if error:
        print(-1)
        sys.exit()
    
    day += 1
            

    if day > 10000:
        print(N*(N-1)//2)
        sys.exit()
    
    
print(day)
    
    


Measured memory_bytes: 57820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p;
    for(int i = 0; i < n; ++i){
        int x; cin >> x;
        p.push_back(x);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < k; ++i){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    string s;
    cin >> s;

    REP(i, 1, s.length()){
        if(s[i-1] == 'A' && s[i] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    
    cout << "No" << endl;
    
    

    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> H(N), DP(N);
  for (int i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }
  DP.at(0) = 0;
  DP.at(1) = abs(H.at(1) - H.at(0));
  for (int i = 2; i < N; i++)
  {
    int a = DP.at(i - 2) + abs(H.at(i) - H.at(i - 2));
    int b = DP.at(i - 1) + abs(H.at(i) - H.at(i - 1));
    DP.at(i) = min(a, b);
  }
  cout << DP.at(N - 1) << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    
    int S,h,m,s;
    scanf("%d", &S);
    
    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600) - m*60;

    printf("%d:%d:%d\n",h,m,s);
}



Measured memory_bytes: 2104
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <sstream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define min(a, b) (a > b ? b : a)

struct Item {
    int price;
    std::vector<std::string> recipe;
};

int main() {
    std::map<std::string, Item> dict;
    int n;
    while (std::cin >> n && n) {
        std::string s, t;
        int p;
        rep(i, n) {
            std::cin >> s >> p;
            dict[s].price = p;
        }

        int k, l;
        std::cin >> k;
        rep(i, k) {
            std::cin >> s >> l;

            std::getline(std::cin, t);
            std::stringstream ss(t);
            std::copy(std::istream_iterator<std::string>(ss), {},
                      std::back_inserter(dict[s].recipe));
        }

        std::function<int(std::string)> min_cost = [&](std::string name) {
            int res = dict[name].price;
            if (dict[name].recipe.size() == 0) return res;

            int rec = 0;
            for (auto i : dict[name].recipe) rec += min_cost(i);
            return min(res, rec);
        };

        std::cin >> s;
        std::cout << min_cost(s) << std::endl;
        dict.clear();
    }
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int A,B;	cin>>A>>B;
	if(abs(A-B)<=2)	cout<<"Yay!"<<endl;
	else	cout<<":("<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;


int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        string s,t;
        cin >> s >> t;
        int n = s.length();
        int m = t.length();
        LL dp[n+2][m+2];
        for(int i = 0 ; i <= n ; i++)
        {
                for(int j = 0 ; j <= m ; j++)
                {
                        dp[i][j] = 0;
                }
        }
        for(int i = 1 ; i <= n ; i++)
        {
                for(int j = 1 ; j <= m ; j++)
                {
                        if(s[i-1] == t[j-1])
                        {
                                dp[i][j] = dp[i-1][j-1] + 1;
                        }
                        else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
                }
        }
        string ans = "";
        int i = n , j = m;
        while(1)
        {
                if(i == 0 || j == 0) break;
                if(dp[i][j] == dp[i-1][j])
                {
                        i--;
                        continue;
                }
                if(dp[i][j] == dp[i][j-1])
                {
                        j--;
                        continue;
                }
                ans += s[i-1];
                i--;j--;
        }
        reverse(ans.begin() , ans.end());
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 70656
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

po = onem()

print(a[po-1])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=1; i <= t; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

void solve()
{
	int a; cin >> a;
	cout << a + a * a + a * a * a;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;
int a[4][MAXN];
int b[MAXN];
int c[MAXN], d[MAXN];

void read(){
	scanf("%d", &n);
	for(int i = 1; i <= 3; i++){
		for(int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);
	}	
}

int solve(){
	for(int i = 1; i <= n; i++){
		int p = a[1][i], q = a[2][i], r = a[3][i];
		if (q % 3 != 2) return 0;
		if (p + r != q * 2) return 0;
		if (abs(p - q) != 1 || abs(r - q) != 1) return 0;
		if (p < r)
			b[i] = r / 3;
		else
			b[i] = -p / 3;
	}	
	for(int i = 1; i <= n; i++){
		if (abs(b[i]) % 2 != i % 2)
			return 0;
	}
	for(int i = 1; i <= n; i++){
		c[abs(b[i])] = i;
	}
	
	if (n == 3){
		if (b[1] == 1 && b[2] == 2 && b[3] == 3) return 1;
		if (b[1] == -3 && b[2] == -2 && b[3] == -1) return 1;
		
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		int x = c[i];
		if (x != i){
			d[i] = b[x] * ((x - i) % 4 == 0 ? 1 : -1);
			b[i+1] *= -1;
			b[x] = b[i] * ((x - i) % 4 == 0 ? 1 : -1);
			c[abs(b[x])] = x;
		}
		else
			d[i] = b[i];
	}
	for(int i = 1; i <= n - 2; i++){
		if (d[i] < 0){
			d[i + 2] *= -1;
		}
	}
	return d[n-1] > 0 && d[n] > 0;
	/*
	for(int i = 1; i <= n; i++)
		cout<<b[i]<<' '; cout<<endl;
	int p = 0, q = 0;
	for(int i = 1; i <= n; i++){
		if (i & 1){
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				p++;
		}
		else{
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				q++;
		}
	}
	cout<<p<<' '<<q<<endl;
	return p % 2 == q % 2;*/
}

void printans(int flag){
	puts(flag ? "Yes" : "No");
}
	

int main(){
	int T = 1;
//	cin>>T;
	while(T--){
		read();
		;
		printans(solve());
	}
	return 0;
} 


Measured memory_bytes: 2688
#include<stdio.h>
int main()
{
    int N,r,c=0;
    scanf("%d",&N);
    while(N!=0)
    {
      r=N%10;
      N=N/10;
      if(r==7)
      c++;
    }
    if(c>=1)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1660
import math

def main():
    N = int(input())
    difficulty_list = list(map(int, input().split(" ")))
    big_list = sorted(difficulty_list, reverse=True)
    index = int(N/2)
    upper = big_list[index-1]
    lower = big_list[-index]
    count = upper - lower
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,co=0;
    cin>>a>>b;
    
    for(int i=1;i<=a;i++){
        if(i<a){
                for(int j=1;j<=31;j++){
                if(i==j) co++;
            }
        }else{
            for(int j=1;j<=b;j++){
                if(i==j) co++;
            }
        }
    }
    
    cout<<co<<endl;
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int doubletCount = 0;
            for (int i = 0; i < n; i++) 
            {
                var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var (d1, d2) = (inputs[0], inputs[1]);

                if (d1 == d2) 
                {
                    doubletCount++;
                    if (doubletCount >= 3) 
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
                else 
                {
                    doubletCount = 0;
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 28160
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (A > 12) {
            System.out.println(B);
        } else if (A > 5) {
            System.out.println(B / 2);
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 21844
def main():
    n = int(input())
    nums = input().split()
    for i in range(len(nums)):
        nums[i] = int(nums[i])
    max_diff = 0
    for i in range(len(nums)):
        for j in range(i, len(nums)):
            diff = abs(nums[i] - nums[j])
            if diff > max_diff:
                max_diff = diff
    print(max_diff)

main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, k;
  string s;
  cin >> n >> s >> k;
  rep(i,n){
    if(s[i]!=s[k-1]){
      s[i] = '*';
    }
  }
  print(s);
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll h,w,m;
        cin>>h>>w>>m;
        map<pair<ll,ll>,ll>v;
        map<ll,ll>r,c;
        ll r1=0,c1=0;
        loop(i,1,m)
        {
            ll x,y;
            cin>>x>>y;
            v[{x,y}]++;
            r[x]++;
            c[y]++;
            r1=max(r1,r[x]);
            c1=max(c1,c[y]);
        }
        vector<ll>rr,cc;
        for(auto a:r)
        {
            if(a.ss==r1)
            {
                rr.pb(a.ff);
            }
        }
        for(auto a:c)
        {
            if(a.ss==c1)
            {
                cc.pb(a.ff);
            }
        }
        //debug(r1,c1,x,y);
        bool f=true;
        ll p=sz(rr)-1,q=sz(cc)-1;
            loop(j,0,p)
            {
                loop(k,0,q)
                {
                    if(v[{rr[j],cc[k]}]==0)
                        {
                            f=false;
                            break;
                        }
                }
                if(f==false) break;
            }

        if(f)
        {
            cout<<r1+c1-1;
        }
        else cout<<r1+c1;
    }
    return 0;
}


Measured memory_bytes: 67732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vll A(N), B(N);
    vector<pair<ll, ll>> BA(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
        BA[i] = {B[i], A[i]};
    }
    sort(all(BA));
    ll now = 0;
    for (auto &&i : BA)
    {
        ll b = i.first, a = i.second;
        now += a;
        if (now > b)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 6528
n = int(input())
a =[]
for i in range(n):
    a.append(int(input()))
#n = 10000
p = []   
pc = [True for _ in range(10001)]
pc[0] = False
pc[1] = False

for i in range(2,10001):
    if pc[i]:
        #print(i, pc[i])
        p.append(i)
        for j in range(i,10001,i):
            pc[j] = False

cnt = 0
for i in a:
    if i<=10000:
        if i in p:
            cnt += 1
    else:
        isp = True
        for j in p:
            if i%j == 0:
                isp = False
                break
        if isp:
            cnt += 1

print(cnt)


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

int main(){
    int i, n, res1 = 0, res2 = 0;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    res2 = a[n-1];
    res1 = a[0];
    for(i=1; i<n-1; i++){
        if(a[i] < 0){
            res2 -= a[i];
        }else{
            res1 -= a[i];
        }
    }
    cout << res2 - res1 << '\n';
    res2 = a[n-1];
    res1 = a[0];
    for(i=1; i<n-1; i++){
        if(a[i] < 0){
            cout << res2 << ' ' << a[i] << '\n';
            res2 -= a[i];
        }else{
            cout << res1 << ' ' << a[i] << '\n';
            res1 -= a[i];
        }
    }
    cout << res2 << ' ' << res1;
    return 0;
}

Measured memory_bytes: 2304
//#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<math.h>
//#include<time.h>
//#include<complex>
#include<algorithm>
using namespace std;

int n,K;
#define maxn 311
char s[maxn];
int f[maxn][maxn][maxn];
int main()
{
	scanf("%s",s+1); n=strlen(s+1); scanf("%d",&K);
	for (int i=1;i<=n;i++)
		for (int j=0;j<=K;j++)
			f[i][i][j]=1;
	for (int len=1;len<n;len++)
		for (int i=1;i<=n-len;i++)
		{
			int j=i+len;
			for (int k=0;k<=K;k++)
			{
				f[i][j][k]=max(f[i][j][k-1],max(f[i][j-1][k],f[i+1][j][k]));
				if (s[i]==s[j]) f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k]+2);
				if (s[i]!=s[j] && k) f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-1]+2);
			}
		}
	printf("%d\n",f[1][n][K]);
	return 0;
}

Measured memory_bytes: 114432
macro_rules! input {
    ($t:ty) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty ;) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ; $n:expr) => {
        (0..$n).map(|_|
            input!($t)
        ).collect::<Vec<_>>()
    };
}

fn main(){
    let n = input!(usize);
    println!("{}", n*(n+1)/2);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



int main() {
  ll n;
  cin >> n;
  string s1,s2;
  cin >> s1 >> s2;

  ll MOD = 1000000007;

  ll ref = 0;
  ll ans = 1;
  ll now = -1;

  while(ref<=n-1){
    if(s1[ref]!=s2[ref]){
      if(now==1){
        ans *= 2;
        ans %= MOD;
      }
      else if(now==2){
        ans *= 3;
        ans %= MOD;
      }
      else{
        ans *= 6;
      }
      now = 2;
      ref += 2;
    }
    else{
      if(now==1){
        ans *= 2;
        ans %= MOD;
      }
      else if(now==2){
        
      }
      else{
        ans *= 3;
      }
      now = 1;
      ++ref;
    }
    // cout << ref << " " << ans << endl;
  }

  cout << ans << endl;



}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class MyClass
{
    class Card : IEquatable<Card>
    {
        public string egara { get; set; }
        public int num { get; set; }

        public bool Equals(Card obj)
        {
            return (this.egara == obj.egara && this.num == obj.num);
        }
    }


    static void Main(string[] args)
    {
        List<Card> list = new List<Card>();
        string[] egara = { "S", "H", "C", "D" };
        foreach (var item in egara)
        {
            for (int i = 0; i < 13; i++)
            {
                Card card = new Card();
                card.egara = item;
                card.num = i + 1;
                list.Add(card);
            }
        }
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] str = Console.ReadLine().Split(' ');
            Card card = new Card();
            card.egara = str[0];
            card.num = int.Parse(str[1]);
            list.Remove(card);
        }
        foreach (var item in list)
        {
            Console.WriteLine("{0} {1}", item.egara, item.num);
        }
    }
}


Measured memory_bytes: 6164
import bisect

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

def calc(k_l, k_r):
	v_l = v_list[0:k_l]
	if k_r == 0:
		v_r = []
	else:
		v_r = v_list[-k_r:]
	
#	print(v_l, v_r)
	v_s = v_l + v_r
	v_s.sort()
	
	minus_count = bisect.bisect_left(v_s, 0)
	
	k_d = min(K - k_l - k_r, minus_count)
#	print(v_s, K - k_l - k_r, minus_count)
	v_s = v_s[k_d:]
#	print(v_s)
	return sum(v_s)

max = calc(0, 0)
nk_min = min(N, K)
for k_l in range(0, K + 1):
	for k_r in range(0, nk_min - k_l + 1):
#		print(k_l, k_r)
		score = calc(k_l, k_r)
		if score > max:
			max = score
print(max)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LLINF 1<<63-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007
#define NUM 100001
int cmp(const void *x,const void *y){
  return *(int*)x-*(int*)y;
}
void swap(int* x,int* y){
  int tmp=*x;*x=*y;*y=tmp;
}

int main() {
  int i,N,M,min=1,ans=0;
  scanf("%d%d",&N,&M);
  int max=N,a,b;
  for(i=0;i<M;i++){
    scanf("%d%d",&a,&b);
    if(a>min)min=a;
    if(b<max)max=b;
  }
  ans=max-min+1;
  if(ans<0)ans=0;
  printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

template<class T>
class SegTree {
    T unit;
    size_t size;
    vector<T> node;
    function<T(T, T)> op, up;
    
    T _query(size_t a, size_t b, size_t k, size_t l, size_t r) {
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return op(c1, c2);
        }
    }
public:
    SegTree(size_t _n, T _unit,  function<T(T, T)> _op, 
            function<T(T, T)> _up) 
            : unit(_unit), op(_op), up(_up) {
        size = 1;
        while(size < _n) size<<=1;
        node.resize(2*size-1, unit);
    }

    T operator[](size_t i) {
        return node[i+size-1];
    }

    void update(size_t x, ll val) {
        x += size-1;
        node[x] = up(node[x], val);
        while(x > 0) {
            x = (x-1)/2;
            node[x] = op(node[2*x+1], node[2*x+2]);
        }
    }
    T query(size_t a, size_t b) {
        return _query(a, b, 0, 0, size);
    }
};

int main() {
    ll n, q;
    cin >> n >> q;
    SegTree<int> st(n, INF,
        [](int a, int b) {return min(a, b);},
        [](int a, int b) {return b;});
    ll c, x, y;
    REP(i, q) {
        cin >> c >> x >> y;
        if(c == 0) st.update(x, y);
        else cout << st.query(x, y+1) << endl;
    }
	return 0;
}


Measured memory_bytes: 3920
import math
nd = input().split(" ")
n = int(nd[0])
d = int(nd[1])
con1 = n >= 1 and n <= 200000
con2 = d >= 0 and d <= 200000
xy_list = list()
distance = 0
plus = 0
count = 0
for i in range (0, n):
    xy_list.append(input())
if con1 == True and con2 == True:
    for i in xy_list:
        xy = i.split(" ")
        x = int(xy[0]) * int(xy[0])
        y = int(xy[1]) * int(xy[1])
        plus = x + y
        distance = math.sqrt(plus)
        if distance <= d:
            count = count + 1
        else:
            count = count
    print(count)
else:
    print()


Measured memory_bytes: 23184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		String  S = sc.next();
		
		String substring = S.substring(K-1, K);
		String lower = substring.toLowerCase();
		
		String front = S.substring(0,K-1);
		String back = S.substring(K,N);
		
		System.out.println(front + lower + back);
		
		sc.close();
		
	}

}


Measured memory_bytes: 22228
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int Q = scan.nextInt();
        List<Long> ans = new ArrayList<>();
        while(Q-->0){
            long A = scan.nextLong();
            long B = scan.nextLong();
            long r = (long)(Math.sqrt((double)A*B));
            if(r*r==A*B && A!=B)--r;
            if(r*(r+1)<A*B){
                ans.add(2*r-1);
            }else{
                ans.add(2*(r-1));
            }


            
        }
        for(long i : ans)System.out.println(i);
    }
}

Measured memory_bytes: 23124
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]

minus = [q for _ in range(n)]
for ai in a:
    minus[ai-1] -= 1

for i in range(n):
    if (minus[i] >= k):
        print('No')
    else:
        print('Yes')



Measured memory_bytes: 10472
#!/usr/bin/env python
# coding: utf-8

# In[9]:


import bisect


# In[10]:


N = int(input())
L = list(map(int, input().split()))


# In[11]:


s_L = sorted(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect.bisect_left(s_L,s_L[i]+s_L[j])-j-1
print(ans)


# In[ ]:






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

stack<char> q;
string t;

int main()
{
	cin >> t;
	int l = t.size();
	for (int i = 0; i < l; i++)
	{
		if (q.empty() == true)
		{
			q.push(t[i]);
			continue;
		}
		if (q.top() == 'S' && t[i] == 'T')
		{
			q.pop();
			continue;
		}
		q.push(t[i]);
	}
	cout << q.size() << endl;

	return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(){
	ll N, A, B;
	cin >> N >> A >> B;
	ll ans = A*(N/(A+B));
	ans += min(A,N%(A+B));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
 
using namespace std;
 
string Calc(int n){
  if(n==0){
    return "0";
  }
 
  string result = "";
 
  while(n!=0){
    int rem = n % (-2);
    n = n / (-2);
 
    if(rem < 0){
      rem += 2;
      n += 1;
    }
 
    result = to_string(rem) + result;
  }
  return result;
}
 
int main(){
  int N;
  cin >> N;
 
  cout << Calc(N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,k,s=0;
  cin>>n>>k;
  for(int i=0;i<n;i++)
    {
      ll x;
      cin>>x;
      if(2*x<(2*abs(k-x)))
        s+=2*x;

      else
        s+=(2*abs(k-x));
    }
    cout<<s<<endl;  
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define x first
#define y second
#define pb push_back
#define len(x) x.size()
#define all(x) x.begin(), x.end()
#define endl "\n"
const ll MOD = 998244353;
#define MAXN 200005

struct mi {
	ll v; explicit operator ll() const { return v; }
	mi() { v = 0; }
	mi(ll _v) {
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) {
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) {
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) {
		return a.v < b.v; }
		friend bool operator<=(const mi& a, const mi& b) {
			return a.v <= b.v; }

	mi& operator+=(const mi& m) {
		if ((v += m.v) >= MOD) v -= MOD;
		return *this; }
	mi& operator-=(const mi& m) {
		if ((v -= m.v) < 0) v += MOD;
		return *this; }
	mi& operator*=(const mi& m) {
		v = v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0);
		return pow(a,MOD-2); }

	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};

typedef vector<mi> vmi;
mi fac[MAXN];
mi facInv[MAXN];

mi choose(mi n, mi k) {
	// if (k == 0) return 1;
	return fac[ll(n)] * facInv[ll(k)] * facInv[ll(n-k)];
}

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

	mi N, M, K;
	cin >> N >> M >> K;

	// initialise maths
	fac[0] = facInv[0] = mi(1);
	for (int i = 1; i < MAXN; i++) {
		fac[i] = fac[i-1] * i;
		facInv[i] = inv(fac[i]);
	}

	mi ans = 0;
	for (mi k = 0; k <= K; k+=1) {
		ans += choose(N-1, k) * M * pow(M-1, ll(N-1-k));
	}
	cout << ans << endl;
}


Measured memory_bytes: 6748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


ll dp[110][10];
int fib[10];
int main() {
	fib[0] = 1;
	fib[1] = 1; fib[2] = 2;
	FOR(i, 3, 10)fib[i] = fib[i - 2] + fib[i - 1];
	m0(dp);
	dp[0][1] = 1;
	int H, W, K;
	cin >> H >> W >> K;
	for (int h = 0; h < H; h++) {
		for (int x = 1; x <= W; x++) {
			dp[h][x] %= MOD;
			if (x == 1) {
				dp[h + 1][x] += dp[h][x] * fib[W - 1];
				dp[h + 1][x + 1] += dp[h][x] * fib[W - 2];
			}
			else if (x == W) {
				dp[h + 1][x] += dp[h][x] * fib[W - 1];
				dp[h + 1][x - 1] += dp[h][x] * fib[W - 2];
			}
			else {
				dp[h + 1][x - 1] += dp[h][x] * (fib[x - 2] * fib[W - x]);

				dp[h + 1][x] += dp[h][x] * (fib[x - 1] * fib[W - x]);

				dp[h + 1][x + 1] += dp[h][x] * (fib[x - 1] * fib[W - x-1]);
			}
		}
	}
	p(dp[H][K]%MOD);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
double c[110][110];
double g[210][210];
int rev[210];
int v[210];
int w[210];
int u[210];
double eps=1e-9;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			scanf("%lf",&c[i][j]);
		}
	}
	for(int i=0;i<210;i++)
		for(int j=0;j<210;j++)
			g[i][j]=999999999;
	int s=b;
	for(int i=0;i<b;i++){
		double dist=0;
		for(int j=0;j<a;j++)dist+=c[i][j]*c[i][j];
		g[s][i]=dist;
		for(int j=0;j<b;j++){
			if(i==j)continue;
			double L=-99999999;
			double R=99999999;
			for(int k=0;k<100;k++){
				double m1=(L*2+R)/3;
				double m2=(L+R*2)/3;
				double d1=0;
				double d2=0;
				for(int l=0;l<a;l++){
					d1+=(c[i][l]*m1-c[j][l])*(c[i][l]*m1-c[j][l]);
					d2+=(c[i][l]*m2-c[j][l])*(c[i][l]*m2-c[j][l]);
				}
				g[i][j]=min(g[i][j],min(d1,d2));
				if(d1<d2)R=m2;
				else L=m1;
			}
		}
	}

	double ret=0;
	int sz=b+1;
	int rt=b;
//		for(int i=0;i<sz;i++){
//		for(int j=0;j<sz;j++)printf("%f ",g[i][j]);
//		printf("\n");
//	}
	while(1){
		for(int i=0;i<sz;i++){
			if(v[i])continue;
			if(rt==i)continue;
			rev[i]=-1;
	//		printf("%d\n",i);
			for(int j=0;j<sz;j++){
				if(v[j])continue;
				if(i==j)continue;
				if(!~rev[i]||g[rev[i]][i]>g[j][i])rev[i]=j;
			}
			
			if(!u[i])ret+=g[rev[i]][i];
			u[i]=1;
		}
		//printf("%d\n",sz);
	//	for(int i=0;i<sz;i++)printf("%d ",rev[i]);printf("\n");
	//	if(sz>6)return 0;
		for(int i=0;i<210;i++)w[i]=0;
		int cnt=0;
		int SZ=sz;
		for(int i=0;i<SZ;i++){
			if(v[i])continue;
			if(w[i])continue;
			if(i==rt)continue;
			int at=i;
			while(1){
				if(w[at]==2){
					cnt++;
					vector<int>vs;
					int a2=at;
					if(w[rt]==2)rt=sz;
					while(1){
						if(w[a2]==1)break;
						vs.push_back(a2);
						w[a2]=1;v[a2]=1;
						a2=rev[a2];
					}
				//	printf("{");
					for(int j=0;j<vs.size();j++){
				//		printf("%d,",vs[j]);
						for(int k=0;k<sz;k++){
							if(g[vs[j]][k]<999999)g[sz][k]=min(g[sz][k],g[vs[j]][k]);
							if(g[k][vs[j]]<999999)g[k][sz]=min(g[k][sz],g[k][vs[j]]-g[rev[vs[j]]][vs[j]]);
						}
					}//printf("}\n");
					sz++;
					break;
				}
				if(w[at]==1)break;
				if(at==rt)break;
				w[at]=2;
				at=rev[at];
			}
			at=i;
			while(1){
				if(w[at]==1)break;
				if(at==rt)break;
				w[at]=1;
				at=rev[at];
			}
		}
		if(!cnt)break;
	}
	printf("%f\n",ret);
}

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

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		ll B;
		cin >> B;
		A[i] -= B;
	}
	if (accumulate(A.begin(), A.end(), 0LL) < 0) {
		cout << -1 << endl;
		return 0;
	}
	ll sum = 0;
	sort(A.begin(), A.end());
	int t = 0;
	while (t < N && A[t] < 0) sum += A[t++];
	if (sum >= 0) {
		cout << 0 << endl;
		return 0;
	}
	reverse(A.begin() + t, A.end());
	for (int i = t; i < N; i++) {
		sum += A[i];
		if (sum >= 0) {
			cout << i + 1 << endl;
			break;
		}
	}
	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  int mp[h][w];
  int i,j,k=0;
  for(i=0;i<h;i++){
    if(i%2==0){
      for(j=0;j<w;j++){
        mp[i][j]=k+1;
        a[k]--;
        if(a[k]==0)k++;
      }
    }else{
      for(j=w-1;j>=0;j--){
        mp[i][j]=k+1;
        a[k]--;
        if(a[k]==0)k++;
      }
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++)cout << mp[i][j] << " ";
    cout << endl;
  }
  return 0;
}


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

long long number(long long na, long long nb) {
  long long temp_max=max(na,nb), temp_min=min(na,nb);
  long long temp=temp_max%temp_min;
  while(temp) {
    temp_max=temp_min;
    temp_min=temp;
    temp=temp_max%temp_min;
  }
  return temp_min;
}

int main() {
  long long a,b;
  cin >> a >> b;
  cout << a*b/number(a,b) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int N,max=0,ans=1;
scanf("%d",&N);
for (int i = 1; i <= N; i++){
  if(i%2!=0){
    continue;
  }else{
    int div = i;
    int counter = 0;
    while (div>0)
    {
      if (i%2!=0){
        break;
      }else{
        counter++;
        div /= 2;
      }
    }

    if (max<counter){
      max = counter;
      ans = i;
    }
    
    
  }
}

printf("%d",ans);

return 0;

}

Measured memory_bytes: 1728
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 300010
char a[N];
int x1[N],x2[N],y1[N],y2[N];
int main()
{
    int i,j,k,n,s;
    scanf("%d%s",&n,a+1);
    s=n;
    x1[0]=0;
    x2[0]=0;
    for(i=1;i<=n;i++)
    {
        x1[i]=x1[i-1];
        x2[i]=x2[i-1];
        if(a[i]=='W')
            x1[i]++;
        else
            x2[i]++;
    }
    y1[n+1]=0;
    y2[n+1]=0;
    for(i=n;i>=1;i--)
    {
        y1[i]=y1[i+1];
        y2[i]=y2[i+1];
        if(a[i]=='W')
            y1[i]++;
        else
            y2[i]++;
    }
    for(i=1;i<=n;i++)
    {
        k=x1[i-1]+y2[i+1];
        s=min(s,k);
    }
    printf("%d\n",s);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int dice[N][2];
    for(int i = 0; i < N; i++){
        cin >> dice[i][0] >> dice[i][1];
    }
    for(int i = 0; i < N-2; i++){
        if(dice[i][0] == dice[i][1] && dice[i+1][0] == dice[i+1][1] && dice[i+2][0] == dice[i+2][1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){ 
  int n;
  cin >> n;
  vector<int>  L(n);
  for(int i = 0; i< n; i++){
     cin >> L[i];
  }
 sort(L.begin(), L.end());
 int ans = 0;
  for(int i = 0; i< n-2; i++){
       for(int j = i+1; j< n-1; j++){
          for(int k = j+1; k<n; k++){
               if(L[i]+L[j] > L[k]) ans++;
           }
        }
     }
  cout << ans << endl;
  return 0;
}

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

vector<int> dp;
vector<string> l;
map<string, int> to;

int dfs(int s, int c){
	if(s == l.size()) return c;
	if(dp[s] <= c) return 99;
	dp[s] = c;
	return min(dfs(to[l[s]], c), dfs(s+1, c+1));
}

main(){
	int n;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		if(s == "goto"){
			cin >> s;
			s[s.size()-1] = ':';
			l.push_back(s);
		}else to[s] = l.size();
	}
	dp = vector<int>(l.size(), 99);
	cout << dfs(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 1260
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] road = new int[m*2];
		int[] ans = new int[n];
		
		for(int i=0; i<m*2; i++){
		    road[i] = sc.nextInt();
		    for(int j=0; j<n; j++){
		        if(road[i]==j+1){
		            ans[j]++;
		        }
		    }
		}
		
		for(int i=0; i<n; i++){
            System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 35800