akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

/*aのb進数時の桁数*/
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
/*aのn乗(mod) 繰り返し二乗法*/
ll modpow(ll a, ll n, ll mod){
    ll s[digits(n,2)],ans=1;
    rep(i,0,digits(n,2)){
        s[i]= i==0 ? a : s[i-1]*s[i-1]%mod ;
        ans*=placenai(n,2,i+1)==1?s[i]:1; ans%=mod;
    }
    return n?ans:1;
}
ll inv[200005],finv[200005];
void makeinv(ll n){
    inv[1]=1;finv[0]=finv[1]=1;
    rep(i,2,n+1){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        finv[i] = finv[i - 1] * inv[i] % MOD1;
    }
}
ll modfac(ll n, ll mod){
    ll x=1;
    rep(i,2,n+1){x*=i%mod;x%=mod;}
    return x;
}

int main(void){
    // char ;
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    // ll [n];
    // makeinv(200005);
    // ll np1 = modfac(n+1,MOD1);
    ll l=(0+k-1)*k/2, r=(n+n-k+1)*k/2;
    rep(i,k,n+2){
        ans+= (r-l) +1 ;
        ans = mod(ans);
        l+=i;
        r+=n-i;
        // printf("%lld ",ans);
    }

    
    printf("%lld\n",mod(ans) );
    return 0;
}


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

ll tenpow(ll n) {
  ll tmp = 1; REP(i, n) tmp *= 10;
  return tmp;
}

int main() {
  ll n; cin >> n;
  ll top = n; ll digit = 1;
  while (top > 9) {
    top /= 10;
    ++digit;
  }
  
  cout << ((n + 1) % tenpow(digit - 1) == 0 ?
           top + 9 * (digit - 1):
           top - 1 + 9 * (digit - 1)) << endl;
  
  return 0;
}

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

int main() {

  int num[32] = {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};
  int K;
  cin >> K;

  cout << num[K-1] << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[111111];
  cin>>a;
  int count=0,n=strlen(a);
  for(int i=0;i<strlen(a);i++){
    if(i%2==0&&a[i]=='0') count++;
    if(i%2==1&&a[i]=='1') count++;
  }
  cout<<min(count,n-count)<<endl;
  return(0);
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!

l = []

for i in range(9):
    # print(i + 1)
    for j in range(9):
        # print(j + 1)
        
        l.append((i + 1) * (j + 1))
        
# print(l)

N = int(input())
if N in l:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		for(;;){
			String tile[][] = new String[22][22];
			int num = 1;
			int num_before = 0;
			for(int i = 0; i < 22; i++){
				for(int j = 0; j < 22; j++){
					tile[i][j] = "#";
				}
			}
			int W = scan.nextInt();
			int H = scan.nextInt();
			if(W == 0 && H == 0)
				break;
			for(int i = 1; i <= H; i++){
				String tile_row = scan.next();
				for(int j = 0; j < W ; j++){
					tile[i][j + 1] = tile_row.substring(j,j + 1);
				}
			}
			for(int i = 0; i <= W * H; i++){
				for(int j = 1; j <= H; j++){
					for(int l = 1; l <= W; l++){
						if(tile[j][l].equals("@")){
							if(tile[j - 1][l].equals(".")){
								tile[j - 1][l] = "@";
								num++;
							}
							if(tile[j + 1][l].equals(".")){
								tile[j + 1][l] = "@";
								num++;
							}
							if(tile[j][l - 1].equals(".")){
								tile[j][l - 1] = "@";
								num++;
							}
							if(tile[j][l + 1].equals(".")){
								tile[j][l + 1] = "@";
								num++;
							}
						}
					}
				}
				if(num == num_before)
					break;
				num_before =num;
			}
			System.out.println(num);
		}
	}
}

Measured memory_bytes: 41932
def q3():
    """C - Vacation"""
    N = int(input())

    dp = [[0]*N for i in range(3)]
    dp[0][0], dp[1][0], dp[2][0] = (int(i) for i in input().split())

    if N == 1:
        print(max([dp[0][0], dp[1][0], dp[2][0]]))
        return

    a, b, c = (int(i) for i in input().split())
    dp[0][1] = max(dp[1][0], dp[2][0]) + a
    dp[1][1] = max(dp[0][0], dp[2][0]) + b
    dp[2][1] = max(dp[1][0], dp[0][0]) + c

    if N == 2:
        print(max([dp[0][1], dp[1][1], dp[2][1]]))
        return

    for i in range(1, N-1):
        a, b, c = (int(i) for i in input().split())
        dp[0][i+1] = max(dp[1][i], dp[2][i]) + a
        dp[1][i+1] = max(dp[0][i], dp[2][i]) + b
        dp[2][i+1] = max(dp[1][i], dp[0][i]) + c
    print(max([dp[0][-1], dp[1][-1], dp[2][-1]]))


if __name__ == '__main__':
    q3()

Measured memory_bytes: 14920
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#define maxn 500011
using namespace std;
 
int n;
 
char s[maxn];
int DP[maxn][3],inf=0x3f3f3f3f;
int sl[maxn],sr[maxn];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	DP[1][1]=DP[2][1]=-inf;
	DP[1][0]=DP[2][0]=0;
	int one=0,cnt=0;
	for (int i=1;i<=n;i++){
		if (s[i]=='1') one++;
		else cnt++,sl[i]=one,one=0;
	}
	one=0;
	for (int i=n,tot=cnt;i>=1;i--){
		if (s[i]=='1') one++;
		else sr[i]=one,one=0,tot--;
	}
	DP[0][0]=0;DP[0][1]=DP[0][2]=-inf;
	int last=0,ans=0;
	for (int i=1;i<=n;i++) if (s[i]=='0'){
		DP[i][0]=max(DP[last][0],max(DP[last][1],DP[last][2]));
		DP[i][1]=sl[i] && sr[i]?max(DP[last][0]+sl[i],
									sl[i]>=1?DP[last][1]+sl[i]-1:-inf)
								:-inf;
		DP[i][2]=sl[i] && sr[i]?max(max(DP[last][0]+sr[i],sl[i]>=2?DP[last][1]+sr[i]:0),
			                        sl[i]>=1?DP[last][2]+sr[i]-1
			                                :-inf)		
							   :-inf;
		ans=max(ans,max(DP[i][0],max(DP[i][1],DP[i][2])));
		last=i;
//		cout<<DP[i][0]<<' '<<DP[i][1]<<' '<<DP[i][2]<<endl;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

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

}


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

using namespace std;

void solve()
{
	vector<int> left(4);
	vector<int> right(4);
	double sight_left, sight_right;
	while(cin >> sight_left >> sight_right)
	{
		if(sight_left >= 1.1)
		{
			++left[0];
		}
		else if(sight_left >= 0.6)
		{
			++left[1];
		}
		else if(sight_left >= 0.2)
		{
			++left[2];
		}
		else if(sight_left < 0.2)
		{
			++left[3];
		}

		if(sight_right >= 1.1)
		{
			++right[0];
		}
		else if(sight_right >= 0.6)
		{
			++right[1];
		}
		else if(sight_right >= 0.2)
		{
			++right[2];
		}
		else if(sight_right < 0.2)
		{
			++right[3];
		}
	}
	for(int i = 0; i < 4; ++i)
	{
		cout << left[i] << " " << right[i] << endl;
	}
}

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

Measured memory_bytes: 1224
import sys

def solve():
    A, B, K = map(int, input().split())
    if A <= K:
        K -= A
        A = 0
    else:
        A -= K
        K = 0

    if K > 0:
        if B <= K:
            K -= B
            B = 0
        else:
            B -= K
            K = 0
    print(A, B)

    return 0

if __name__ == "__main__":
    solve()


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

int main() {
  cout << fixed << setprecision(7);
  double r;
  cin >> r;
  double ans = (r * 2.0000000) * PI;
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 9e18
#define mod 1000000007

ll A,B,C,D;
map<ll,ll> mem;
ll dfs(ll n){
  if(n==0)return 0;
  if(mem.find(n)!=mem.end())return mem[n];
  ll res=INF;
  if(n<=INF/D)minch(res,n*D);

  ll r2=n%2,r3=n%3,r5=n%5;
  minch(res,min({dfs((n-r2)/2LL)+A+r2*D,dfs((n-r3)/3LL)+B+r3*D,dfs((n-r5)/5LL)+C+r5*D}));
  r2=(2-n%2)%2,r3=(3-n%3)%3,r5=(5-n%5)%5;
  if((n+r2)/2LL<n)minch(res,dfs((n+r2)/2LL)+A+r2*D);
  if((n+r3)/3LL<n)minch(res,dfs((n+r3)/3LL)+B+r3*D);
  if((n+r5)/5LL<n)minch(res,dfs((n+r5)/5LL)+C+r5*D);
  return mem[n]=res;
}

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

  ll T;
  cin>>T;
  while(T--){
    ll N;
    cin>>N>>A>>B>>C>>D;
    mem.clear();
    cout<<dfs(N)<<endl;
  }

  return 0;
}


Measured memory_bytes: 4400
#include <stdio.h>

int main(){
  int n,i,j,a[13][4],x,p;
  char d;
  for(i=0;i<13;i++){
    for(j=0;j<4;j++){
      a[i][j]=0;
    }
  }
  scanf("%d",&n);
  for(p=0;p<=n;p++){
    scanf(" %c",&d);
    scanf("%d",&x);
    if(d=='S'){
      a[x-1][0]=1;
    } else if(d=='H'){
      a[x-1][1]=1;
    } else if(d=='C'){
      a[x-1][2]=1;
    } else if(d=='D'){
      a[x-1][3]=1;
    }
  }
  for(j=0;j<4;j++){
    for(i=0;i<13;i++){
      if(a[i][j]==0){
        if(j==0){
          printf("S %d\n",i+1);
        } else if(j==1){
          printf("H %d\n",i+1);
        } else if(j==2){
          printf("C %d\n",i+1);
        } else if(j==3){
          printf("D %d\n",i+1);
        }
      }
      }
    }
}

Measured memory_bytes: 2664
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf = 1e4+9,MX = 1e18+9;
ll k,n,a[inf],b[inf],dp[inf];

int main(){

    cin>>k>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];

    for(ll i=1;i<=k;i++){
        dp[i] = MX;
        for(ll j=1;j<=n;j++){
            dp[i] = min(dp[i] , dp[ max(0ll,i-a[j]) ]+b[j] );
        }
    }
    cout<<dp[k]<<endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int R = sc.nextInt();
      if(R<1200){
        System.out.println("ABC");
      }else if(R<2800){
        System.out.println("ARC");
      }else{
        System.out.println("AGC");
      }
    }
}

Measured memory_bytes: 35672
package main

import "fmt"

func main() {
	var x, h, m, s int
	fmt.Scan(&x)
	h = x / (60 * 60)
	m = (x - h * 60 * 60) / 60
	s = x % 60
	fmt.Printf("%d:%d:%d\n", h, m ,s)
}


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

int main() {
    ll n;
    cin>>n;
    vector<tuple<string,ll,ll>> sp;
    for(ll i=0;i<n;i++) {
        string q;
        ll w;
        cin >> q>>w;
        sp.push_back(make_tuple(q,100-w,i+1));
    }
    sort(sp.begin(),sp.end());
    for(ll i=0;i<n;i++) {
        cout <<get<2>(sp[i])<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int k, a, b; cin >> k >> a >> b;
    cout << (b / k == (a - 1) / k ? "NG" : "OK") << "\n";
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    ll x=1000,kabu=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int cnt=0;
    while(1){
        if(cnt==n-1){
            x+=kabu*a[n-1];
            break;
        }
        if(a[cnt]<a[cnt+1]){
            int cnt1=cnt+1;
            kabu+=x/a[cnt];
            x-=a[cnt]*(x/a[cnt]);
            while(1){
                if(a[cnt1]>a[cnt1+1] || cnt1==n-1){
                    x+=kabu*a[cnt1];
                    kabu=0;
                    cnt=cnt1;
                    break;
                }else{
                    ++cnt1;
                }
            }
        }else{
            ++cnt;
        }
    }
    cout << x << "\n";
    return 0;
}   

Measured memory_bytes: 3616
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

H,W = inpl()
inMAP = [['#']*(W+2)] + [['#']+list(input())+['#'] for y in range(H)] + [['#']*(W+2)]

ans = -1
for sx in range(1,W+1):
    for sy in range(1,H+1):
        if inMAP[sy][sx] == "#":
            continue

        MAP = [m[:] for m in inMAP]

        q = queue.Queue()
        q.put([sx,sy,0])
        while not q.empty():
            x,y,n = q.get()
            if MAP[y][x] == '.':
                MAP[y][x] = n
                q.put([x-1,y,n+1])
                q.put([x+1,y,n+1])
                q.put([x,y-1,n+1])
                q.put([x,y+1,n+1])


        for x in range(1,W+1):
            for y in range(1,H+1):
                if MAP[y][x] != "#":
                    ans = max(ans,MAP[y][x])


print(ans)


Measured memory_bytes: 65492
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, K;
	string S;
	cin >> N >> K >> S;
	if(S[K-1] == 'C')
		S[K-1] = 'c';
	else if(S[K-1] == 'B')
		S[K-1] = 'b';
	else
		S[K-1] = 'a';
	cout << S << endl;	
}

Measured memory_bytes: 256
from collections import deque


n, q = map(int, input().split())

S = [deque([]) for _ in range(n)]


for _ in range(q):

    command, *list_num = input().split()

    t = int(list_num[0])

    if   command == "0":
        # enqueue(t, x)
        x = int(list_num[1])
        S[t].append(x)
        
    elif command == "1":
        # front(t)
        if S[t]:
            print(S[t][0])
    elif command == "2":
        # dequeue(t)
        if S[t]:
            S[t].popleft()
    else:
        raise




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

int main(void) {
  long long int N, H;
  vector<int> a, b;
  cin >> N >> H;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }

  int a_max = *max_element(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());

  long long int ans = 0;
  for (int i = 0; H > 0 && b[i] > a_max; i++) {
    H -= b[i];
    ans++;
  }
  while (H > 0) {
    H -= a_max;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <string>
using namespace std;
string s;
int main(){
	cin >> s;
	int i,n = s.size(),cnt = 0;
	for(i=0;i<n;i++){
		if(s[i]!=s[n - 1 - i]){
			cnt++;
		}
	}
	cout << cnt/2 << endl;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    int ans = 0;
    if (abs(n-m) < 2) {
        int fn = 1,fm = 1;
        FOR(i,2,n+1) fn = modm(fn,i);
        FOR(i,2,m+1) fm = modm(fm,i);
        ans = modm(fn,fm);
    }

    if (abs(n-m) == 0) ans = modm(ans,2);

    cout << ans << endl;

    return 0;
}

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

int main()
{
    string abc;
    cin >> abc;
    
    int cnt = 0;
    
    for (int i = 0; i < abc.length()/2; i++)
    {
        if (abc[i] != abc[abc.length()-1-i]) cnt++;
    }
    
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++)dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



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

int main() {
  string s;
  cin >> s;
  int a = 0;
  for(int i=0; i<s.size()/2; i++) {
    if(s[i]!=s[s.size()-i-1])
      a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n,t,x,s;
int main()
{
    cin>>n;
    t=n;
    while(t--)
    {
        cin>>x;
        s+=x;
    }
    cout<<s-n;
}


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

int main(){
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	for(int a = 0; a < N; ++a) {
		for(int b = 0; b < D; ++b) {
			cin >> X[a][b];
		}
	}

	int cnt = 0;

	for(int a = 0; a < N; ++a) {
		for(int b = a + 1; b < N; ++b) {
			double res = 0;
			for(int c = 0; c < D; ++c) {
				res += (X[a][c] - X[b][c]) * (X[a][c] - X[b][c]);

				if(c == D - 1) {
					if(floor(sqrt(res)) == sqrt(res)) {
						cnt++;
					}
				}
			}
		}
	}

	cout << cnt << endl;
}


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

int main(){
	int n;

	std::string str;
	std::cin>>str;

	if (str == "Sunny") {
		std::cout << "Cloudy" << std::endl;
	}

	if (str == "Cloudy") {
		std::cout << "Rainy" << std::endl;
	}

	if (str == "Rainy") {
		std::cout << "Sunny" << std::endl;
	}

	//std::cout<<n<<std::endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations

n, k = map(int, input().split())
star = []
max_k = (n - 1) * (n - 2) // 2
delta = max_k - k
cnt = 0
if k <= max_k:
    ans = []
    for i in range(2, n + 1):
        star.append((1, i))
        cnt += 1

    if delta > 0:
        kumiawase = list(combinations(range(2, n+1), 2))
        for j in range(delta):
            kumi = kumiawase[j]
            star.append(kumi)
            cnt += 1
    print(cnt)
    for pair in star:
        print(*pair, sep=" ")
else:
    print(-1)


Measured memory_bytes: 43376
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct trie{
	bool leaf;
	trie* node[2];
	trie(){
		leaf = false;
		for(int i = 0; i < 2; i++){
			node[i] = (trie*)0;
		}
	}

	void insert(const string &s){
		// cout << "s = " << s << endl;
		trie* r = this;
		for(int i = 0; i < s.length(); i++){
			// cout << s[i] << " ";
			int c = s[i]-'0';
			if(!r->node[c]) r->node[c] = new trie;
			r = r->node[c];
		}
		// printf("\n");
		r->leaf = true;
	}

	// bool find(const string &s){
	// 	const trie* r = this;
	// 	for(int i = 0; i < s.length(); i++){
	// 		char c = s[i];
	// 		if(!r->node[c]) return false;
	// 		r = r->node[c];
	// 	}
	// 	return r->leaf;
	// }

	// void check(const string &s){
	// 	cout << s << "    ";
	// 	cout << (find(s)?"":"not") << " find" << endl;
	// }
};


ll grundy(ll x){
	if(x== 0) return 0;
	ll res = 1;
	while(x%(res*2)==0) res*=2;
	return res;
}
ll n,l;
ll ans = 0;

void solve(trie *t,ll d){
	// cout << "d = " << d << "  " << endl;
	if(t->leaf || d>=l) return;

	if((!t->node[0]&&t->node[1]) || (!t->node[1]&&t->node[0])){
		// cout << "d = " << d << "  " << endl;
		ans ^= grundy(l-d);
		// cout << l-d << " " <<  grundy(l-d) << endl;
	}
	for(int i = 0; i < 2; i++){
		if(t->node[i]) solve(t->node[i],d+1);
	}
	// for(int i = 0; i < 2; i++){
	// 	if(!t->node[i]){
	// 		//cout << d+1 << endl;
	// 		ans ^= grundy(d+1);
	// 		// cout << ans << endl;
	// 	}
	// 	else solve(t->node[i],d+1);
	// }
	return;
}

int main()
{
	cin >> n >> l;
	trie t;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		t.insert(s);
	}
	solve(&t,(ll)0);
	// cout << ans << endl;
	cout << (ans!=(ll)0?"Alice":"Bob") <<endl;

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    bool ans = true;

    if (n % 2 == 0){
        for (int i = 0; i < n / 2; ++i) if (s[i] != s[i + n / 2]) ans = false;
    }
    else ans = false;

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
    
}

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

// https://github.com/atcoder-live/library/blob/master/mint.cpp
const std::int64_t mod = 1000000007;
struct mint {
    std::int64_t x; // typedef long long ll;
    mint(std::int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(std::int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
std::istream& operator>>(std::istream& is, const mint& a) { return is >> a.x;}
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;}


vector<ll> memo;

mint dfs(ll s) {
    if (s == 0) return 1;
    if (s <= 2) return 0;
    if (memo[s] >= 0) return memo[s];
    mint ret = 0;
    for (ll x = 3; x <= s; ++x) {
        ret += dfs(s - x);
    }
    return memo[s] = ret.x;
}

int main() {
    ll S; cin >> S;
    memo = vector<ll>(2005, -1);
    cout << dfs(S) << endl;
    return 0;
}


Measured memory_bytes: 3644
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;


void dfs(vv32& adj, vbool& visited, int s, vector<ll>& dpb, vector<ll>& dpw){
	// NOTE MAKE VISITED TO BE 0 BEFORE STARTING
	// s is the source vertex

	visited[s]=1;

	for(v32::iterator it = adj[s].begin(); it!=adj[s].end(); ++it){
		if(!visited[*it]){
			dfs(adj, visited, *it, dpb, dpw);
			dpb[s] = (dpb[s] * (dpw[*it])%MOD )%MOD;
			dpw[s] = (dpw[s] * (dpb[*it] + dpw[*it])%MOD )%MOD;
		}
	}
}

void makegraph(vv32& adj, int n){
	// n is number of vertices
	// m is number of edges

	adj.resize(n);
	int x, y;

	forn(i,n-1){
		cin >> x >> y;
		adj[x-1].pb(y-1);
		adj[y-1].pb(x-1);
	}

}

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

	vv32 adj;
	int n;

	cin >> n;

	makegraph(adj, n);

	vector<ll> dpb, dpw;

	forn(i,n){
		dpb.pb(1);
		dpw.pb(1);
	}

	vbool visited;
	forn(i,n) visited.pb(false);

	dfs(adj, visited, 0, dpb, dpw);

	cout << setprecision(20) << (dpb[0] + dpw[0])%MOD;


}


Measured memory_bytes: 14364
/*
[abc141] A - Weather Prediction
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

string S;

string solve() {
    if (S == "Sunny") {
        return "Cloudy";
    }
    if (S == "Cloudy") {
        return "Rainy";
    }
    return "Sunny";
}

int main() {
    cin >> S;

    cout << solve() << endl;

    return 0;
}


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


int main(){
    ll n,m;cin>>n>>m;
    ll p[11],c[11];
    rep(i,0,n)cin>>p[i]>>c[i];
    ll an=1e9;
    for(ll i=0;i<(1<<n);i++){
        ll sum=0,poi=0;
        bool fl[11];
        rep(j,0,n)fl[j]=0;
        rep(j,0,n){
            if(i&(1<<j)){
                sum+=p[j];
                poi+=100*p[j]*(j+1)+c[j];
                fl[j]=1;
            }
        }
        if(poi<m){
            for(int j=n-1;j>=0;j--){
                if(fl[j])continue;
                ll tmp=p[j];
                while(tmp!=1){
                    sum++;poi+=100*(j+1);
                    tmp--;
                    if(poi>=m)break;
                }
                if(poi>=m)break;
            }
        }
        if(poi>=m)an=min(an,sum);
    }
    cout<<an<<endl;
}

    









Measured memory_bytes: 256
#!/usr/bin/ruby

class Dice
  def initialize
    @num = { n:5, e:3, s:2, w:4, u:1, d:6 }
  end

  def move(d)
    case d
    when 'North' then
      tmp = @num[:u]
      @num[:u] = @num[:s]
      @num[:s] = @num[:d]
      @num[:d] = @num[:n]
      @num[:n] = tmp

    when 'East' then
      tmp = @num[:w]
      @num[:w] = @num[:d]
      @num[:d] = @num[:e]
      @num[:e] = @num[:u]
      @num[:u] = tmp

    when 'West' then
      tmp = @num[:u]
      @num[:u] = @num[:e]
      @num[:e] = @num[:d]
      @num[:d] = @num[:w]
      @num[:w] = tmp

    when 'South' then
      tmp = @num[:u]
      @num[:u] = @num[:n]
      @num[:n] = @num[:d]
      @num[:d] = @num[:s]
      @num[:s] = tmp

    when 'Right' then
      tmp = @num[:s]
      @num[:s] = @num[:e]
      @num[:e] = @num[:n]
      @num[:n] = @num[:w]
      @num[:w] = tmp

    when 'Left' then
      tmp = @num[:s]
      @num[:s] = @num[:w]
      @num[:w] = @num[:n]
      @num[:n] = @num[:e]
      @num[:e] = tmp

    end
  end

  def getPoint
    return @num[:u]
  end
end

loop do
  n = gets.to_i
  break if n == 0

  dice = Dice.new
  sum = dice.getPoint
  n.times do
    dice.move(gets.chomp!)
    sum += dice.getPoint
  end
  puts sum
end

Measured memory_bytes: 8780
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  vector<int> cnt(26,0),temp(26,0);
  int n;
  cin>>n;
  string s;
  REP(i,n){
    cin>>s;
    REP(j,s.size()){
      if(i==0){
        cnt[s[j]-'a']++;
      }else{
        temp[s[j]-'a']++;
      }
    }
    
    if(i!=0){
      REP(j,26){
        cnt[j] = min(cnt[j],temp[j]);
        temp[j]=0;
      }
    }
  }
  
  string ans="";
  char c;
  REP(i,26){
    c = i + 'a';
    REP(j,cnt[i]){
      ans += c;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
ans = 0
for i in range(n):
    sum_a1 = sum(a1[:i+1])
    sum_a2 = sum(a2[i:])
    s = sum_a1 + sum_a2
    if s > ans:
        ans = s

print(ans)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	nums := make([]int, 10001)
	for x := 1; x < 100; x++ {
		for y := 1; y < 100; y++ {
			for z := 1; z < 100; z++ {
				i := (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)
				if i <= 10000 {
					nums[i]++
				}
			}
		}
	}

	for i := 1; i <= n; i++ {
		fmt.Println(nums[i])
	}
}


Measured memory_bytes: 1984
#include <cstdio>

int main(void)
{
    int r, c, buf, sum, j;
    scanf("%d %d", &r, &c);
    int t[r+1][c+1];
    for(int i=0; i<r+1; i++) t[i][c] = 0;
    for(int i=0; i<c+1; i++) t[r][i] = 0;
    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
        {
            scanf("%d", &buf);
            t[i][j] = buf;
            t[i][c] += buf;
            t[r][j] += buf;
        }
        t[r][c] += t[i][c];
    }
    for(int i=0; i<r+1; i++)
    {
        for(j=0; j<c; j++)
            printf("%d ", t[i][j]);
        printf("%d\n", t[i][j]);
    }

    return 0;
}


Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
	a.push_back(inf);
    sort(begin(a),end(a),greater<ll>());
	auto solve=[&](ll x){
		if(x<=p) return true;
		if(a[x]+m<a[p]) return false;
		ll now=v;
		now-=1;
		now-=p-1;
		now-=n-x;
		if(now<=0) return true;
		ll cnt=0;
		FOR(j,p,x){
			cnt+=a[x]+m-a[j];
		}
		return cnt>=m*now;
	};
	ll ok=1,ng=n+1,mid;
	while(ng-ok>1){
		mid=(ok+ng)/2;
		if(solve(mid)) ok=mid;
		else ng=mid;
	}
	cout<<ok<<endl;
}

Measured memory_bytes: 1792
s=input()
a=[]
count=0
minus=0
for i in range(len(s)):
  if(minus==1):
    minus=0
    continue

  if(s[i]=="-"):
    a.append(int("-"+s[i+1]))
    minus=1
  else:
    a.append(int(s[i]))

for i in [1,-1]:
  for j in [1,-1]:
    for k in [1,-1]:
      if(a[0] + a[1]*i + a[2]*j + a[3]*k == 7):
        if(i==1):
          i_2="+"
        else:
          i_2="-"
        if(j==1):
          j_2="+"
        else:
          j_2="-"
        if(k==1):
          k_2="+"
        else:
          k_2="-"

        print(str(a[0])+i_2+str(a[1])+j_2+str(a[2])+k_2+str(a[3])+"=7")
        exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	int ans=1,odd=1;
	rep(i,n){
		cin>>a[i];
		ans*=3;
		if(a[i]%2==0){
			odd*=2;
		}
	}
	cout<<ans-odd<<endl;
}

Measured memory_bytes: 256
# |b−c|< a < b+c
# a+b>c  かつ b+c>a かつ c+a>b

n = int(input())
side = list(map(int,input().split()))
ans = 0
for i in range(0,len(side)):
    for j in range(i+1,len(side)):
        for k in range(j+1,len(side)):
            if(abs(side[j]-side[k]) < side[i] < side[j]+side[k] and side[i]!=side[j]and side[k]!=side[j]and side[i]!=side[k]):
                ans+=1
                # print(side[i],side[j],side[k])
print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    ll i,j,n,m,total_W;
    cin >> n >> total_W;
    ll W[n+5],tk[n+5],total_tk[n+5][total_W+5];
    for(i=1; i<=n; i++)
        cin >> W[i] >> tk[i];
    for(i=0; i<=n; i++)
    {
        for(j=0; j<=total_W; j++)
        {
            if(i==0 || j==0) total_tk[i][j]=0;
            else if(j>=W[i])
            {
                total_tk[i][j] = max(tk[i]+total_tk[i-1][j-W[i]],total_tk[i-1][j]);
            }
            else total_tk[i][j]=total_tk[i-1][j];
            // cout <<i<<" "<<j<<" "<<W[i]<<' '<<tk[i]<<' '<<total_tk[i][j]<<endl;
        }
    }
    cout << total_tk[n][total_W]<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
   // cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}



Measured memory_bytes: 82504
import numpy as np
a=[[int(j) for j in input().split()] for i in range(3)]
a=np.array(a)

N=int(input())
for n in range(N):
    s=int(input())
    a=np.where(a-s==0,0,a)

for a1 in zip(*a):
    if len(set(a1))==1:
        print("Yes")
        exit(0)
for a1 in a:
    if len(set(a1))==1:
        print("Yes")
        exit(0)
x=np.diag(a)
if len(set(x))==1:
    print("Yes")
    exit(0)
y=np.diag(np.rot90(a))

if len(set(y))==1:
    print("Yes")
    exit(0)
print("No")


Measured memory_bytes: 12512
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#include <utility>
#define INF 9999999999
using namespace std;
typedef long long int ll;

int main() {
	int N, M;
	cin >> N;
	vector<string> blue(N);
	for (int i = 0; i < N; i++) cin >> blue[i];
	cin >> M;
	vector<string> red(M);
	for (int i = 0; i < M; i++) cin >> red[i];

	vector<string> red_b;
	vector<int> red_b_n;
	red_b.push_back(red[0]);
	red_b_n.push_back(1);
	for (int i = 1; i < M; i++) {
		int flag = 0;
		for (int j = 0; j < red_b.size(); j++) {
			if (red_b[j] == red[i]) {
				red_b_n[j]++;
				flag++;
				break;
			}
		}
		if (flag) continue;
		red_b.push_back(red[i]);
		red_b_n.push_back(1);
	}

	vector<string> blue_b;
	vector<int> blue_b_n;
	blue_b.push_back(blue[0]);
	blue_b_n.push_back(1);
	for (int i = 1; i < N; i++) {
		int flag = 0;
		for (int j = 0; j < blue_b.size(); j++) {
			if (blue_b[j] == blue[i]) {
				blue_b_n[j]++;
				flag++;
				break;
			}
		}
		if (flag) continue;
		blue_b.push_back(blue[i]);
		blue_b_n.push_back(1);
	}
	
	int ans = 0;
	for (int i = 0; i < blue_b.size(); i++) {
		int flag = 0;
		for (int j = 0; j < red_b.size(); j++) {
			if (blue_b[i] == red_b[j]) {
				if (ans < blue_b_n[i] - red_b_n[j]) {
					ans = blue_b_n[i] - red_b_n[j];
				}
				flag++;
				break;
			}
		}
		if (flag) continue;
		if (ans < blue_b_n[i]) ans = blue_b_n[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#define N 105
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
using namespace std;

char s[N];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	
	fi(i, 0, n - 1){
		if(s[i] == 'A' && s[i + 1] == 'C') {
			puts("Yes");
			return 0;
		}
	}
	
	puts("No");
}

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

int main(){
    long long int a=0, b=0;
    string c;
    cin >> a >> c >> b;
    if(c[0]=='+'){
        cout << a+b << endl;
    }else if(c[0]=='-'){
        cout << a-b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

dict = defaultdict(int) #lamda:0

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

for key in D_li:
	dict[key] += 1
	
M = list(input())
T_li = list(map(int,input().split()))

for key in T_li:
	dict[key] -= 1
	if dict[key] < 0:
		print('NO')
		sys.exit()

print('YES')

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N);
    vector<ll> B(M);
    vector<ll> C(N);
    vector<ll> D(M);

    REP(i, N){
        cin >> A[i];
    }
    REP(i, M){
        cin >> B[i];
    }

    REP(i, N){
        if(i==0){
            C[i] = A[i];
        }
        else{
            C[i] = C[i-1] + A[i];
        }
    }

    REP(i, M){
        if(i==0){
            D[i] = B[i];
        }
        else{
            D[i] = D[i-1] + B[i];
        }
    }

    // REP(i, N){
    //     cout << C[i] << endl;
    // }

    // REP(i, M){
    //     cout << D[i] << endl;
    // }

    ll ans = 0;
    REP(i, N){
        ll L;
        L = K-C[i];
        if(L<0) break;

        vector<ll>::iterator position;  // auto position; で良い．
        ll idx_lower;

        position = upper_bound(D.begin(), D.end(), L);  // 3 を二分探索
        idx_lower = distance(D.begin(), position);

        ans = max(ans, i+1+idx_lower);
    }

    REP(i, M){
        if(K-D[i] < 0) break;
        ans = max(ans, i+1);
    }
    
    cout << ans << endl;
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n, k;
string s;

int acc[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);
  cin >> s;

  if (s[0] == '0') {
    acc[0] = 1;
  }

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

  for (int i = 1; i < n; ++i) {
    acc[i] += acc[i - 1];
  }

  acc[n] = acc[n - 1] + 1;

  if (acc[n - 1] <= k) {
    printf("%d\n", n);
    return 0;
  }

  ans = -1;

  for (int i = 0; i < n; ++i) {
    int buff = (s[i] == '0') ? k - 1 : k;

    int end = upper_bound(acc + i, acc + n + 1, acc[i] + buff) - acc;

    ans = max(ans, end - i);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ **/


typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
int INF=1e9+7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a,b;
    cin>>a>>b;
    int A=a.size();
    int B=b.size();
    int dp[A+1][B+1];
    for(int i=0;i<=A;i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=B;i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=A;i++)
    {
        for(int j=1;j<=B;j++)
        {
            if(a[i-1]==b[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    //cout<<dp[A][B]<<endl;
    string str;
    int I=A;
    int J=B;
    while(I>0&&J>0)
    {
        if(I==0||J==0)break;
        if(dp[I-1][J]==dp[I][J])
            I--;
        else if(dp[I][J-1]==dp[I][J])
            J--;
        else
        {
            str=str+a[I-1];
            I--;
            J--;
        }
    }
    reverse(str.begin(),str.end());
    pf(str);
}


Measured memory_bytes: 35456