akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 998244353

using namespace std;

bool cmp(string s, string p) {
    return s.size() < p.size();
}

int main()
{
    int n;
    cin >> n;
    vector<int> dp(3);
    for(int i = 0; i < n; i++) {
        vector<int> n_dp(3);
        vector<int>c(3);
        for(int j = 0; j < 3; j++) {
            cin >> c[j];
        }
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(j != k) {
                    n_dp[k] = max(n_dp[k], dp[j] + c[k]);
                }
            }
        }
        dp = n_dp;
    }
    cout << max(max(dp[0], dp[1]), dp[2]) << "\n";
    return 0;
}



Measured memory_bytes: 256
N, K =map(int,input().split())
A = list(map(int,input().split()))
ans = 0

for i in range(len(A)-K+1):
    if i == 0:
        t = sum(A[i:i+K])
    else:
        t -= A[i-1]
        t+= A[i+K-1]
    ans = max(ans,t)

print((ans+K)/2)


Measured memory_bytes: 25060
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n,q=MI()
    #ソース　https://juppy.hatenablog.com/entry/2018/11/17/蟻本_python_Binary_Indexed_Tree_競技プログラミング
    #A1 ... AnのBIT(1-indexed)
    BIT = [0]*(n+1)
    #idxの一番下のbit
    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum
    
    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= n:
            BIT[idx] += x
            idx += idx&(-idx)
        return
    lis=LI()
    for i in range(n):
        BIT_update(i+1,lis[i])
    for i in range(q):
        a,b,c=MI()
        if a==0:
            BIT_update(b+1,c)
        else:
            ans=BIT_query(c)-BIT_query(b)
            print(ans)



        
        
        
        
        
    
if __name__=="__main__":
    main()



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

#define int long long

signed main(void){
    int n; cin >>n;
    vector<int>p(n);
    int cnt=0;
    for(int i=0;i<n;i++) cin >> p[i];
    for(int i=0;i<n;i++){
        // cout << i+1 << ' ' << p[i] << endl;
        if(i+1==p[i]){
            if(i!=p.size()-1) p[i+1] = p[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <tuple>
#include <utility>
#include <functional>
#include <sys/time.h>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, m, n) for(int i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

constexpr int SZ = 26;
constexpr int D = 365;
array<int, SZ> C;
array<array<int, SZ>, D> S;

int main(void){
	int tmp;
	cin >> tmp;
	rep(i, SZ) cin >> C[i];
	rep(i, D) rep(j, SZ) cin >> S[i][j];

	rep(i, D) cout << i % SZ + 1 << endl;

	return 0;
}


Measured memory_bytes: 3672
#include <iostream>

int main() {
  int distance, big_jump_length;
  std::cin >> distance >> big_jump_length;
  if (distance % big_jump_length == 0) {
    std::cout << distance / big_jump_length << std::endl;
    return 0;
  }
  std::cout << distance / big_jump_length + distance % big_jump_length << std::endl;
}



Measured memory_bytes: 3092
#include <cstdio>

int main()
{
  char s[101];
  int h, w;
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; ++i)
  {
    scanf("%s", s);
    puts(s);
    puts(s);
  }
  return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
N = int(input())
S = list(map(int, input().split()))
N -= 1
ans = 0
for d in range(1,N+1):
    a = N-d
    res = 0
    p,q = N,0
    while a >= d:
        if a <= N-a and N%d == 0:
            break
        p -= d
        q += d
        res += S[p] + S[q]
        if res > ans:
            ans = res
        a -= d
    
print(ans)   

Measured memory_bytes: 14332
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,b=0,aa[110000],cnt=0;
pair<string,int> p[220000];
string s,ss[220000],x;
char c;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>p[i].first>>p[i].second;
    }
    cin>>x;
    rep(i,n){
        if(b==1){
            cnt+=p[i].second;
        }
        if(p[i].first==x){
            b=1;
        }
    }
    cout<<cnt;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> p(n+1,0);
	vector<int> q(n+1,0);
	vector<int> p2(n + 1, 0);
	vector<int> q2(n + 1, 0);
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
		p2[i] = i;
	}
	for (int i = 1; i <= n; ++i) {
		cin >> q[i];
		q2[i] = i;
	}

	int pI = 1;
	for (int i = 1; i <= n; ++i) {
		if (p[i] == p2[i]) {

		}
		else {
			vector<int> p22 = p2;
			int count = 0;
			for (int j = i + 1; j <= n; ++j) {
				++count;
				p22[j] = p2[j - 1];
				if (p2[j] == p[i]) {
					break;
				}
			}

			p2 = p22;

			int k = 1;
			for (int j = 1; j <= n - i; ++j) {
				k *= j;
			}
			pI += k * count;
		}
	}

	int qI = 1;
	for (int i = 1; i <= n; ++i) {
		if (q[i] == q2[i]) {

		}
		else {
			int count = 0;
			vector<int> q22 = q2;
			for (int j = i + 1; j <= n; ++j) {
				++count;
				q22[j] = q2[j - 1];
				if (q2[j] == q[i]) {
					break;
				}
			}

			q2 = q22;

			int k = 1;
			for (int j = 1; j <= n - i; ++j) {
				k *= j;
			}
			qI += k * count;
		}
	}

	if (pI - qI < 0) {
		cout << qI - pI << endl;
	}
	else {
		cout << pI - qI << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

typedef pair<double,double> P;
double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};


struct circle{
  point p;
  double r;
};

vector<point> circles_cross(circle a, circle b){
    vector<point> ret;
     
    double x = a.p.x - b.p.x , y = a.p.y - b.p.y;
    double L = x * x + y * y;
    if(L > pow(a.r+b.r,2))return ret;
     
    L = sqrt(L);
    double C = atan2(b.p.y-a.p.y,b.p.x-a.p.x);
    double alpha = acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));
     
    point r1,r2;
    r1.x = a.p.x + cos(C+alpha) , r1.y = a.p.y + sin(C+alpha);
    r2.x = a.p.x + cos(C-alpha) , r2.y = a.p.y + sin(C-alpha);
     
    ret.push_back(r1) , ret.push_back(r2);
     
    return ret;
}

int main(void){
  int n;
  circle a[100];

  while(cin >> n,n){
    vector<P>d;

    for(int i=0;i<n;i++){
      scanf("%lf,%lf",&a[i].p.x,&a[i].p.y);
      a[i].r=1;
    }
    /*
      for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
      double L=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
      if(L>2.0000)continue;
      double theta=atan2(y[j]-y[i],x[j]-x[i]);
      double a=acos(L/2);
      d.push_back(make_pair(x[i]+cos(theta+a),y[i]+sin(theta+a)));
      d.push_back(make_pair(x[i]+cos(theta-a),y[i]+sin(theta-a)));
      }
      }
    */
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	vector<point> p=circles_cross(a[i],a[j]);
	for(int k=0;k<p.size();k++){
	  d.push_back(make_pair(p[k].x,p[k].y));
	}
      }
    }
    /*
    for(int i=0;i<d.size();i++){
      cout << d[i].first << " " <<d[i].second << endl;
    }
    */
    int count,ans=1;
    for(int i=0;i<d.size();i++){
      count=0;
      
      for(int j=0;j<n;j++){
	if(pow(d[i].first-a[j].p.x,2)+pow(d[i].second-a[j].p.y,2)<=1.0+EPS)count++;
      }
	ans=max(ans,count);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,r; cin>>n>>r;
	if(n>=10) cout << r << endl;
	else{
		cout << r+100*(10-n) << endl;
	}


  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
    ll N;
    cin >> N;
    ll ans = 0;


    for(ll r=1;r*r<N;r++){
        if(N%r==0){
            if(N>r*r+r)ans += (N-r)/r;
        }
    }

    // for (ll r = 1; r*r <= N; ++r) {
    //     if ((N-r) % r == 0 && (N-r)/r > r) ans += (N-r)/r;
    // }
    //N=k(m+1)かつk<mが満たされればいい


    cout << ans << endl;

}

/*
r<mということに気づけなかった
r<m であってこれは r2+r>N と同値である


*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll Solve(){
    ll N,K; cin>>N>>K;
    vec d(N);
    rep(i,N) cin>>d[i];
    ll SUM=0, MAX=0;
    rep(i,N){
        MAX=max(MAX,d[i]);
        SUM+=d[i];
    }
    if(SUM-N<=K) return 1;
    ll OK=MAX, NG=1;
    while(OK>NG+1){
        ll MID=(OK+NG)/2;
        ll Count=0;
        rep(i,N) Count+=(d[i]+MID-1)/MID;
        Count-=N;
        if(Count<=K) OK=MID;
        else NG=MID;
    }
    return OK;
}
int main(){
    cout<<Solve()<<endl;
}


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

int main()
{
  int num;
  int dig = 0;
  int sum = 0;
  cin >> num;
  int X = num;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  int fx = sum;
  if (X%fx == 0)
    cout << "Yes" <<endl;
  else
    cout << "No" <<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use std::mem::swap;
use nalgebra::{min, max};


#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    ab: [(Usize1, Usize1); m]
    }
    let mut uf = UnionFind{par: vec![], siz: vec![]};
    uf.init(n);
    for i in 0..m {
        uf.unite(ab[i].0, ab[i].1);
    }
    let mut ans = 0;
    for i in 0..n {
        ans = max(ans, uf.size(i));
    }
    println!("{}", ans);
}
#[derive(Default)]
struct UnionFind {
    par: Vec<usize>,
    siz: Vec<usize>,
}

#[allow(dead_code)]
impl UnionFind {
    fn init(&mut self, n: usize) {
        for i in 0..n {
            self.par.push(i);
            self.siz.push(1);
        }
    }

    fn find(&mut self, x: usize) -> usize {
        let ele = self.par[x];
        return if ele == x {
            x
        } else {
            self.par[x] = self.find(ele);
            self.par[x]
        };
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            return false;
        }
        if self.siz[x] < self.siz[y] {
            swap(&mut x, &mut y)
        }
        self.siz[x] += self.siz[y];
        self.par[y] = x;
        true
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.find(x);
        self.siz[root]
    }
}



Measured memory_bytes: 10996
//インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

//型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef string answerType;

//変数宣言
ll N;
ll M;
std::vector<string> input;
std::vector<string> Ai;
std::vector<string> Bi;
answerType answer;

//関数のプロトタイプ宣言
//入力の取得
void getInput();
//答えを求める
answerType calcAnswer();

//メイン関数
int main() {
	//入力の取得
	getInput();

	//答え
	answerType answer = calcAnswer();

	//答えの出力
	std::cout << answer << std::endl;

	//正常終了
	return EXIT_SUCCESS;
}

//入力の取得
void getInput() {
	string temp;
	std::getline(std::cin, temp);
	input.push_back(temp);
	std::getline(std::cin, temp);
	input.push_back(temp);
	std::getline(std::cin, temp);
	input.push_back(temp);
}

//答えを求める
answerType calcAnswer() {
	return input[0].substr(0, 1) + input[1].substr(1, 1) + input[2].substr(2, 1);
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 998244353

using namespace std;

int N, M, Q;
vector<int> a(55), b(55), c(55), d(55);
vector<int> A(11, 1);
int ans = 0;

void solve(int n)
{
    if (n == N)
    {
        for (int i = A[n - 1]; i <= M; i++)
        {
            A[n] = i;
            int sum = 0;
            for (int j = 0; j < Q; j++)
            {
                if (A[b[j]] - A[a[j]] == c[j])
                {
                    sum += d[j];
                }
            }
            ans = max(sum, ans);
        }
        return;
    }
    
    for (int i = A[n - 1]; i <= M; i++)
    {
        A[n] = i;
        solve(n + 1);
    }
}

void solve()
{
    cin >> N >> M >> Q;

    for (int i = 0; i < Q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    solve(1);
    cout << ans << endl;

}


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

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



Measured memory_bytes: 3652
from math import *
from statistics import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    while input()!="0":
        aa = list(map(int, input().split()))
        print(pstdev(aa))

main()



Measured memory_bytes: 7084
#include <iostream>
#include <vector>
#include <algorithm>

void put( std::vector<int> &b ){
  for( int i=0; i<b.size(); ++i ){
    if (i){ std::cout << " "; }
    std::cout << b[i];
  }
  std::cout << std::endl;
}

int main(){
  int n; std::cin >> n;
  std::vector<int> b(n);
  for( int &v : b ){ std::cin >> v; }
  put(b);
  for( int i=1; i<n; ++i ){
    for( int j=0; j<i; ++j ){
      if ( b[j] >= b[i] ){
        b.insert( b.begin() + j, b[i] );
        b.erase( b.begin() + i + 1 );
        break;
      }
    }
    put(b);
  }
}


Measured memory_bytes: 3132
#include <stdio.h>

int main(void) {
   
   int N,X;
   
   scanf("%d%d",&N,&X);
   
   int i;
   int L[N];
   
   for (i = 0; i < N; i++) {
      scanf("%d",&L[i]);
   }
   
   int D[N+1];
   
   D[0] = 0;
   
   int ans = 0;
   for (i = 1;i < N+1;i++) {
      D[i] = D[i - 1] + L[i - 1];
      if (D[i] <= X) {
         ans++;
      }
   }
   
   if (D[0] <= X) {
      ans++;
   }
   
   printf("%d\n",ans);
   
   return 0;
   
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define all(a)      a.begin(),a.end()
#define getc getchar_unlocked
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  int x,y;
  cin >> x >> y;
  y-=(2*x);
  if(y<0)
    {cout << "No\n";return;}
  if((y%2)==0 && (x-(y/2))>=0)
    cout << "Yes\n";
 else
    cout << "No\n";
  return;
} 

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


Measured memory_bytes: 3608
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    int ans=0;
    for(int i=0; i<S.size(); i++){
        ans += (S.at(i)=='+'?1:-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<vector<int>>flag((4000), vector<int>(1 << 9));
vector<vector<pair<double,double>>>memo((4000),vector<pair<double,double>>(1<<9));
pair<double,double>  operator+(const pair<double, double>&l, const pair<double, double>&r) {
	return make_pair(l.first+r.first,l.second+r.second);
}

 pair<double,double> solve(const int a_win,const vector<int>&as, const vector<int>&bs, bitset<9>a_used, bitset<9>b_used) {
	int a_id=a_win+400*a_used.count()+200;
	int b_id=b_used.to_ulong();
	if(flag[a_id][b_id])return memo[a_id][b_id];
	else{
		flag[a_id][b_id]=true;
		pair<double,double> sum;
		int num=0;
		for (int a_next = 0; a_next < 9; ++a_next) {
			for (int b_next = 0; b_next < 9; ++b_next) {
				if (!a_used[a_next] && !b_used[b_next]) {
					a_used[a_next]=true;
					b_used[b_next]=true;
					int next_a_win=a_win;
					if (as[a_next] > bs[b_next]) {
						next_a_win+=as[a_next]+bs[b_next];
					}
					else {
						next_a_win-=as[a_next]+bs[b_next];
					}
					sum=sum+solve(next_a_win,as,bs,a_used,b_used);
					a_used[a_next]=false;
					b_used[b_next]=false;
					num++;
				}
			}
			if(!a_used[a_next])break;
		}

		if (num == 0) {
			if (a_win == 0) {
				return memo[a_id][b_id]=make_pair(0,0);
			}
			else if (a_win > 0) {
				return memo[a_id][b_id]=make_pair(1,0);
			}else{
				return memo[a_id][b_id]=make_pair(0,1);
			}
		}else{
			return memo[a_id][b_id]=make_pair(sum.first/num,sum.second/num);
		}
		
	}
}
int main() {
	int T;cin>>T;
	while (T--) {
		for (int i = 0; i < (4000); ++i) {
			for (int j = 0; j < (1 << 9); ++j) {
				flag[i][j]=false;
			}
		}
		vector<int>as,bs;
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < 9; ++j) {
				int c;cin>>c;
				if(i)bs.emplace_back(c);
				else as.emplace_back(c);
			}
		}
		bitset<9>bs_a,bs_b;
		int a_win=0;
		auto  per=solve(a_win,as,bs,bs_a,bs_b);
		cout<<per.first<<" "<<per.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 43048
#include <iostream>
#include <vector>

int N;
using namespace std;
vector<int> eds[100008];
vector<int> cst[100008];
long long dp[100008][2];
int subtreesize[100008];
int getmin(int va,int vb) {
	if(va>vb) return vb;
	return va;
}
void dfs(int now,int from) {
	subtreesize[now]=1;
	for(int i=0;i<eds[now].size();i++) {
		if(eds[now][i]!=from) {
			dfs(eds[now][i],now);
			int temp=subtreesize[eds[now][i]];
			dp[now][0]+=dp[eds[now][i]][0]+(long long)cst[now][i]*getmin(temp,N-temp-1)*2;
			subtreesize[now]+=subtreesize[eds[now][i]];
			//dp[now][1]+=dp[eds[now][i]][1]+(long long)cst[now][i]*getmin(temp-1,N-temp)*2;
		}
	}
	for(int i=0;i<eds[now].size();i++) {
		if(eds[now][i]!=from) {
			int temp=subtreesize[eds[now][i]];
			long long temp1=dp[eds[now][i]][0]+(long long)cst[now][i]*getmin(temp,N-temp-1)*2;
			long long temp2=dp[eds[now][i]][1]+(long long)cst[now][i]*getmin(temp-1,N-temp)*2;
			if(dp[now][1]<dp[now][0]-temp1+temp2) dp[now][1]=dp[now][0]-temp1+temp2;
		}
	}
	for(int i=0;i<eds[now].size();i++) {
		if(eds[now][i]!=from) {
			int temp=subtreesize[eds[now][i]];
			long long temp1=dp[eds[now][i]][0]+(long long)cst[now][i]*getmin(temp,N-temp-1)*2;
			long long temp2=dp[eds[now][i]][0]+(long long)cst[now][i]*(getmin(temp,N-temp)*2-1);
			if(dp[now][1]<dp[now][0]-temp1+temp2) dp[now][1]=dp[now][0]-temp1+temp2;
		}
	}
}
int main() {
	cin >> N;
	for(int i=1;i<N;i++) {
		int va,vb,vc;
		cin >> va >> vb >> vc;
		eds[va].push_back(vb);
		eds[vb].push_back(va);
		cst[va].push_back(vc);
		cst[vb].push_back(vc);
	}
	dfs(1,-1);
	cout << dp[1][1] << endl;
	return 0;
}


Measured memory_bytes: 21120
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

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

int main(){
    int n, m;
    cin >> n >> m;
    vi s(m, 0);
    for(int i=0;i<m;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int si;
            cin >> si;
            si--;
            s[i] |= (1 << si);
        }
    }
    vector<int> p(m);
    for(auto&& x:p)cin >> x;
    int ret = 0;
    for(int i=0;i<(1 << n);i++){
        int g = 1;
        for(int j=0;j<m;j++){
            int f = s[j] & i;
            if(__builtin_popcount(f) % 2 != p[j])g = 0;
        }
        ret+=g;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt(), n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        if (n == 100) n++;
        sb.append(n);
        for (int i = 0; i < d; i++) {
            sb.append("00");
        }
        System.out.println(sb.toString());
    }
}

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

int main() {
    string s, ns;
    cin >> s;

    ll a = 0, cnt = 0;
    rep(i, s.size() - 1) {
        if (s[i] == 'B' && s[i + 1] == 'C') {
            cnt += a;
            i++;
        } else if (s[i] == 'A')
            a++;
        else
            a = 0;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
  int n,p;

  while(cin>>n>>p&&n!=-1&&p!=-1){
    vector<int> prime;

    if(n<=3){
      n=5;
      prime.push_back(2);
      prime.push_back(3);
      prime.push_back(5);
    }
    for(int i=n+1;i<=101000;i++){
      if(prime.size()==200) break;
      for(int j=2;j<=(int)sqrt(i);j++){
        if(i%j==0) break;
        if(j==(int)sqrt(i)){
          prime.push_back(i);
        }
      }
    }

    vector<int> sum;
    for(int i=0;i<prime.size();i++){
      for(int j=i;j<prime.size();j++){
 //       if(n==100000) cout << prime[i] << " + " << prime[j] << endl;
        sum.push_back(prime[i]+prime[j]);    
      }
    }

    sort(sum.begin(), sum.end());
    cout << sum[p-1] << endl;
  }

  return 0;
}

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

int main() {
  int N,S=0,m=100000000;
  cin>>N;
  vector<int>v(N);
  for(int i=0;i<N;i++){
    cin>>v[i];
    if(m>v[i]){
      S++;
      m=v[i];
    }
  }
  cout<<S<<endl;
}

Measured memory_bytes: 4036
#include<stdio.h>
int main(){
int H,W,i,j;

while(1){
scanf("%d %d",&H,&W);
if((H==0)&&(W==0))break;

for(i=0;i<H;i++){
for(j=0;j<W;j++){

if(i%2==1){
if(j%2==0)printf(".");
else printf("#");
}else{
if(j%2==0)printf("#");
else printf(".");
}
}
printf("\n");
}
printf("\n");
}

return 0;
}

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

int main()
{
	int d;
	while(cin>>d)
	{
		int right=600/d;
		int ans=0;
		for(int i=d;i<600;i+=d)
		{
			ans+=d*i*i;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	fmt.Println(max(a+b, a-b, a*b))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
using namespace std;
 
 
int main(){
    int64_t n,k,ans=0;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
        if(h.at(i)>=k)ans++;
    }
   cout<<ans<<endl;
    
   
    
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
using ll = unsigned long long;
const ll mod = 1000000007;
string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//bool less_sec(const pair<int, int>&a, const pair<int, int>&b) {
//	return a.second > b.second;
//}
int a, b, c, d;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;    
    if(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll factorial[2010000];
ll invfactorial[2010000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD; 
	return ret;
}
int main(void){
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    factorial[0] = 1;

    for (ll i = 1; i < 2010000; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (ll i = 0; i < 2010000; i++){
        ll x, y;
        ll g = extGCD(factorial[i], MOD, x, y);
        while (x < 0) x += MOD;
        x %= MOD;
        invfactorial[i] = x;
    }


    ll total = 0;
    for(ll i = 0; i <= r2; i++){
        total += nCrM(c2 + i, i);
        total %= MOD;
    }
    for(ll i = 0; i <= c2; i++){
        total += nCrM(r2 + i, i);
        total %= MOD;
    }

    ll minus = 0;
    for(ll i = 0; i <= r2; i++){
        minus += nCrM(c1 - 1 + i, i);
        minus %= MOD;
    }

    for(ll i = 0; i < c1; i++){
        minus += nCrM(r2 + i, i);
        minus %= MOD;
    }

    for(ll i = 0; i <= c2; i++){
        minus += nCrM(r1 - 1 + i, i);
        minus %= MOD;
    }
    for(ll i = 0; i < r1; i++){
        minus += nCrM(c2 + i, i);
        minus %= MOD;
    }

    ll plus = 0;
    for(ll i = 0; i < r1; i++){
        plus += nCrM(c1 - 1 + i, i);
        plus %= MOD;
    }

    for(ll i = 0; i < c1; i++){
        plus += nCrM(r1 - 1 + i, i);
        plus %= MOD;
    }
    ll ans = (total - minus) % MOD;
    if(ans < 0) ans += MOD;
    ans += plus;
    ans %= MOD;
    cout << ans << endl;


}   

Measured memory_bytes: 31616
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(n):
    if A[i]<B[i]:
        ans+=A[i]
        B[i]-=A[i]
        rem=min(A[i+1],B[i])
        ans+=rem
        A[i+1]-=rem
    else:
        ans+=B[i]
print(ans)

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

typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x;
		ret %= MOD;
	}
	return ret;
}

int main(){
	ll n,k;
	cin >> n >> k;
	
	ll dp[2][2002] = {};
	ll t = 0, t_ = 1;
	dp[t][1] = 1;
	for(int i = k-1 ; i >= 1 ; i --){
		for(int j = 1 ; j <= n-i ; j ++){
			dp[t_][j] = dp[t_][j-1]+dp[t][j];
			if(dp[t_][j] >= MOD)dp[t_][j] -= MOD;
		}
		swap(t,t_);
	}
	ll ret = 0;
	for(int i = 0 ; i < 2002 ; i ++){
		ret += dp[t][i];
	}
	ret %= MOD;
	if(k < n){
		ret *= modpow(2,n-k-1);
		ret %= MOD;
	}
	cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 2005;
const int MAXN = 200005;
const long long int MOD = 1000000007;
int dp[2*MAXV][2*MAXV], a[MAXN], b[MAXN];
long long int fact[MAXN], invf[MAXN];
long long int ncr(int n, int r)
{
	if(n < r)
		return 0;
	long long int ans = (fact[n]*invf[r])%MOD;
	ans = (ans*invf[n-r])%MOD;
	return ans;
}
long long int power(long long int a, int b)
{
	if(!b)
		return 1;
	long long int ans = power(a, b/2);
	ans = (ans*ans)%MOD;
	if(b%2)
		ans = (ans*a)%MOD;
	return ans;
}
int main()
{
	fact[0] = invf[0] = 1;
	for (int i = 1; i < MAXN; ++i)
	{
		fact[i] = (fact[i-1]*i)%MOD;
		invf[i] = power(fact[i],MOD-2);
	}
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &a[i], &b[i]);
		dp[MAXV - a[i]][MAXV - b[i]]++;
	}
	for (int i = 1; i < 2*MAXV; ++i)
	{
		for (int j = 1; j < 2*MAXV; ++j)
		{
			dp[i][j] = dp[i][j] + dp[i-1][j] + dp[i][j-1];
			while(dp[i][j] >= MOD)
				dp[i][j]-=MOD;
		}
	}
	long long int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans = (ans + dp[MAXV + a[i]][MAXV + b[i]])%MOD;
		ans = (ans + MOD - ncr(2*(a[i] + b[i]),2*b[i]))%MOD;
	}
	ans = (ans*invf[2])%MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 67712
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair

using namespace std;

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

int s[1<<20];
int id[1<<20];
int size;

// k人目の状態をseg-treeで管理
// ノードは区間内の生存者の合計を保持

void init(int n){
	size = 1;
	while(size < n){
		size *= 2;
	}
	rep(i, size*2){
		s[i] = 0;
	}
}

// k番目に登録
void add(int k, int num){
	k += size-1;
	s[k] = 1;
	id[k] = num;
	while(k > 0){
		k = (k-1)/2;
		s[k]++;
	}
}

// k番目を殺す
int kill(int k){
	k += size-1;
	if(s[k] == 0) return 0;
	s[k] = 0;
	while(k > 0){
		k = (k-1)/2;
		s[k]--;
	}
	return 1;
}

// 生存者のn番目の位置を探す
int query(int n, int k, int l, int r){
	if(s[k] < n || s[k] == 0) return -1;
	if(r - l == 1){
		return k-(size-1);
	}
	int chl = k*2+1, chr = k*2+2;
	int ret = query(n, chl, l, (l+r)/2);
	if(ret != -1) return ret;
	return query(n-s[chl], chr, (l+r)/2, r);
}


int main(){
	int q, lim;
	while(cin >> q >> lim, q|lim){
		init(q);
		map<int, int> idmap;
		vector<int> v(q);
		int idx = 0;
		queue<int> que;
		rep(i, q){
			int type, x;
			cin >> type >> x;
			int pos;
			switch(type){
			case 0:
				v[idx] = x;
				idmap[x] = idx;
				que.push(idx);
				add(idx++, x);
				// 生存者がlim人を超えたら左から殺す
				if(s[0] > lim){
					kill(query(1, 0, 0, size));
				}
				break;
			case 1:
				pos = query(x, 0, 0, size);
				kill(pos);
				break;
			case 2:
				pos = query(x, 0, 0, size);
				cout << v[pos] << endl;
				break;
			case 3:
				kill(idmap[x]);
				break;
			}
		}
		cout << "end" << endl;
    }

	return 0;
}

Measured memory_bytes: 29580
#include <stdio.h>
#include <string.h>

struct member
{
  int next;
  int prev;
};

int main(void)
{
  int i;
  int m, n;
  char say[10];
  char num[10];
  struct member mem[1001];
  int mp;

  while(1){
    scanf("%d %d", &m, &n);
    if(m==0 && n==0) break;

    for(i=1; i<=m; i++){
      mem[i].next=i%m+1;
      mem[i].prev=(i+m-2)%m+1;
    }
    mp=1;
    for(i=1; i<=n; i++){
      scanf("%s", say);
      if(mem[mp].next==mp) continue;
      sprintf(num, "%d", i);
      if(i%15==0 && strcmp(say, "FizzBuzz")!=0
	 || i%5!=0 && i%3==0 && strcmp(say, "Fizz")!=0
	 || i%3!=0 && i%5==0 && strcmp(say, "Buzz")!=0
	 || i%3!=0 && i%5!=0 && strcmp(say, num)!=0){
	mem[mem[mp].next].prev=mem[mp].prev;
	mem[mem[mp].prev].next=mem[mp].next;
      }
      mp=mem[mp].next;
    }
    while(mem[mp].prev<mp) mp=mem[mp].prev;
    printf("%d", mp);
    while(mem[mp].next>mp){
      printf(" %d", mem[mp].next);
      mp=mem[mp].next;
    }
    printf("\n");
  }
}

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

const int INF=1e5;
const int N=100;
int n,x,y,a[N],b[N],c[N];
int dp[44][444][444];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>x>>y;
	for(int k=0;k<44;++k)
		for(int i=0;i<444;++i)
			for(int j=0;j<444;++j) 
				dp[k][i][j]=(i==0&&j==0)?0:INF;
	for(int i=1;i<=n;++i)
		cin>>a[i]>>b[i]>>c[i];
	for(int k=1;k<=n;++k)
		for(int i=0;i<444;++i)
			for(int j=0;j<444;++j){
				dp[k][i][j]=min(dp[k][i][j],dp[k-1][i][j]);
				if(i-a[k]>=0&&j-b[k]>=0)
					dp[k][i][j]=min(dp[k][i][j],dp[k-1][i-a[k]][j-b[k]]+c[k]);
			}
	int res=INF;
	for(int k=1;k<=n;++k)
		for(int i=1;max(x*i,y*i)<444;++i)
			res=min(res,dp[k][x*i][y*i]);
	if(res>=INF) res=-1;
	cout<<res<<'\n';
}




Measured memory_bytes: 37508
from collections import Counter

n = int(input())
ctr= [Counter(input()) for _ in range(n)]

c = ctr[0]
for i in range(1, n):
    for k, v in c.items():
        c[k] = min(ctr[i][k], c[k])

ans = ''
for k, v in sorted(c.items()):
    ans += k * v

print(ans)

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

int main(){
  int i,data[10];
  for( i = 0; i < 10; i++ ){
    cin >> data[i];
  }

  for( i = 0; i < 10; i++ ){
    for ( int j = 0;j < 9; j++ ){
      if ( data[j] < data[j+1]) swap(data[j],data[j+1]);
    }
  }

  for( i = 0; i < 3; i++ ) cout << data[i] << endl;
  return 0;
}

Measured memory_bytes: 1160
L = input()
N = [int(i) for i in list(L)]
def check(n):
  if n == -1:
    return '-'
  else:
    return '+'
for i in range(2):
  for j in range(2):
    for k in range(2):
      if N[0] + N[1] * pow(-1, i) + N[2] * pow(-1, j) + N[3] * pow(-1, k) == 7:
        ii = check(pow(-1, i))
        jj = check(pow(-1, j))
        kk = check(pow(-1, k))
        print(str(N[0]) + ii + str(N[1]) + jj + str(N[2]) + kk + str(N[3]) + "=7")
        exit(0)


Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

print("Yes" if "9" in N else "No")


Measured memory_bytes: 5156
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	int a[n], b[n], c[n - 1];
	for(int i = 0; i < n; i++)
		cin>>a[i];
	for(int i = 0; i < n; i++)
		cin>>b[i];
	for(int i = 0; i < n - 1; i++)
		cin>>c[i];
	int sum = b[a[0] - 1];
	for(int i = 1; i < n; i++){
		sum += b[a[i] - 1];
		if(a[i] - 1 == a[i - 1])
			sum += c[a[i] - 2];
	}
	cout<<sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  long n,k;
  cin>>n>>k;
  vector<long> h(300000);
  ll sum=0;
  for(int i=0; i<n; i++) cin >>h[i];
  if(n<=k) cout << 0 << endl;
  else{
  	sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    for(int i=k; i<n; i++){
    	sum+=h[i];
    }
    cout << sum << endl;
  }
  
}

Measured memory_bytes: 2688
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        String S = scanner.next();
        int A = S.replaceAll("ABC", "").length();
        System.out.println((N - A) / 3);
    }

}



Measured memory_bytes: 24020
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 4
#define true 1
#define false 0

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

void swap(int *x,int *y){
  int tmp=*x;
  *x=*y;
  *y=tmp;
  return ;
}

int getHeuristic(){
  int i,j,sum=0,x;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
    if(t[i][j]==0)continue;
    x=t[i][j]-1;
    sum+=abs(x/4-i)+abs(x%4-j);
    }
  }
  return sum;
}

int dfs(int depth,int prev,int py,int px){
  int h=getHeuristic();
  if(h==0)return true;
  if(depth+h>limit)return false;
  int i;
  for(i=0;i<4;i++){
    if(abs(i-prev)==2)continue;
    int tx=px+dx[i],ty=py+dy[i];
    if(tx<0||ty<0||tx>=N||ty>=N)continue;
    swap(&t[ty][tx],&t[py][px]);
    if(dfs(depth+1,i,ty,tx))return true;
    swap(&t[ty][tx],&t[py][px]);
  }
  return false;
}

void isSolved(int py,int px){
  for(limit=0;;limit++){
    if(dfs(0,99,py,px)){
      printf("%d\n",limit);
      return ;
    }
  }
}

int main(){
  int i,j,px,py;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&t[i][j]);
      if(t[i][j]==0){
        py=i;
        px=j;
      }
    }
  }
  isSolved(py,px);
  return 0;
}



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

int main() {
  ll h, w; cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << (h * w + 1) / 2;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        string Arguments;
        decimal a,b,c,d,e,f,x,y;
        string[] SplittedArguments;
        
        while((Arguments = Console.ReadLine()) != null){
            SplittedArguments = Arguments.Split(' ');

            a = decimal.Parse(SplittedArguments[0]);
            b = decimal.Parse(SplittedArguments[1]);
            c = decimal.Parse(SplittedArguments[2]);
            d = decimal.Parse(SplittedArguments[3]);
            e = decimal.Parse(SplittedArguments[4]);
            f = decimal.Parse(SplittedArguments[5]);
            
            y = (decimal)(c * d - a * f) / (b * d - a * e);
            x = (decimal)(c - b * y) / a;
            
            Console.WriteLine(Math.Round(x, 3) + " " + Math.Round(y, 3));
        }
    }
}

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

int ans=3*2000;
void solve(string a,string b,string c){
  int as=a.size();
  int bs=b.size();
  int cs=c.size();
  vector<bool> ab(as+1,true);
  vector<bool> ac(as+1,true);
  vector<bool> bc(bs+1,true);

  for(int i=0;i<as;i++){
    for(int j=0;j<bs;j++){
      if(i+j>=as) break;
      if(a.at(i+j)=='?' || b.at(j)=='?')  continue;
      if(a.at(i+j)!=b.at(j)){
        ab.at(i)=false;
        break;
      }
    }
  }
  for(int i=0;i<as;i++){
    for(int j=0;j<cs;j++){
      if(i+j>=as) break;
      if(a.at(i+j)=='?' || c.at(j)=='?')  continue;
      if(a.at(i+j)!=c.at(j)){
        ac.at(i)=false;
        break;
      }
    }
  }
  for(int i=0;i<bs;i++){
    for(int j=0;j<cs;j++){
      if(i+j>=bs) break;
      if(b.at(i+j)=='?' || c.at(j)=='?')  continue;
      if(b.at(i+j)!=c.at(j)){
        bc.at(i)=false;
        break;
      }
    }
  }

  for(int i=0;i<=as;i++){
    for(int j=i;j<=as+bs;j++){
      if(!ab.at(i)) continue;
      if(j>=as+1);
      else if(!ac.at(j)) continue;
      if(j-i>=bs+1);
      else if(!bc.at(j-i)) continue;
      int tmp=max(bs,(j-i)+cs);
      tmp=max(as,i+tmp);
      ans=min(ans,tmp);
    }
  }
}

int main(){
  vector<string> S(3);
  for(int i=0;i<3;i++)  cin >> S.at(i);

  sort(S.begin(),S.end());
  do{
    solve(S.at(0),S.at(1),S.at(2));
  }while(next_permutation(S.begin(),S.end()));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int N = 310;
const ll MOD = 998244353;

int dp[N][N][N];
ll dp2[N][N][N];

string s;

void add(ll& a, ll b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> s;
	reverse(ALL(s));
	dp[s.size()][0][0] = 1;
	int n = s.size();

	for (int l = s.size(); l >= 0; --l) {
		for (int i = n - l; i >= 0; --i) {
			for (int j = n - l; j >= 0; --j) {
				if (!dp[l][i][j]) {
					continue;
				}

				if (i) {
					dp[l][i - 1][j] = 1;
				}
				if (j) {
					dp[l][i][j - 1] = 1;
				}
				if (l) {
					dp[l - 1][i][j] = 1;
					if (i && s[l - 1] == '1') {
						dp[l - 1][i - 1][j + 1] = 1;
					}
					if (j && s[l - 1] == '0') {
						dp[l - 1][i + 1][j - 1] = 1;
					}
				}

				if (l >= 2) {
					if (s[l - 1] == '0' || s[l - 2] == '0') {
						dp[l - 2][i + 1][j] = 1;
					}
					if (s[l - 1] == '1' || s[l - 2] == '1') {
						dp[l - 2][i][j + 1] = 1;
					}
				}
			}
		}
	}

	for (int l = 0; l < n; ++l) {
		for (int i = 0; i <= n - l; ++i) {
			for (int j = 0; j <= n - l; ++j) {
				if (dp[l][i][j]) {
					if (i && s[l] == '0') {
						dp[l + 1][i - 1][j] = 1;
					}
					if (j && s[l] == '1') {
						dp[l + 1][i][j - 1] = 1;
					}
				}
			}
		}
	}


	ll ans = 0;
	dp2[0][0][0] = 1;
	for (int l = 0; l <= n; ++l) {
		for (int i = 0; i + l <= n; ++i) {
			for (int j = 0; i + j + l <= n; ++j) {
				if (dp[l][i][j] && l + i + j != 0) {
					//cout << l << " " << i << " " << j << ": " << dp2[l][i][j] << "\n";
					add(ans, dp2[l][i][j]);
				}
				if (l < n && s[l] == '0') {
					add(dp2[l + 1][i][j], dp2[l][i][j]);
				} else {
					add(dp2[l][i + 1][j], dp2[l][i][j]);
				}
				if (l < n && s[l] == '1') {
					add(dp2[l + 1][i][j], dp2[l][i][j]);
				} else {
					add(dp2[l][i][j + 1], dp2[l][i][j]);
				}
			}
		}
	}
	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 143196