akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
const int tambahsimpan=9;
int simpan[20],arr[20],ukuranarr;
LL ans=0,pangkat[20],d;
void isisimpan(){
	for(int i=-9;i>=9;i++)
		simpan[i+tambahsimpan]=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			int temp=i-j;
			simpan[temp+tambahsimpan]++;
		}
	}
}
void isipangkat(){
	pangkat[0]=1;
	for(int i=1;i<=18;i++)
		pangkat[i]=pangkat[i-1]*10LL;
}
int banyakcara(int angka){
	return simpan[angka+tambahsimpan];
}
int caratertentu(int j,int angka){				//kalau angka pertama nya di tentukian
	int i=j+angka;
	return (0<=i&&i<=9)?1:0;
}
int totaldigit(int angka){
	int digit=0;
	while(angka>0)
	{
		digit++;
		angka/=10;
	}
	return digit;
}
void hitungans(){
	LL kali=1;
	for(int i=1;i<=ukuranarr;i++)
	{
		if(i==1)
			kali*=(LL) banyakcara(arr[i])-caratertentu(0,arr[i]);
		else
			kali*=(LL) banyakcara(arr[i]);
	}
	/*cout<<"printing arr"<<endl;
	for(int i=1;i<=ukuranarr;i++)
		cout<<arr[i]<<" ";
	cout<<endl;
	cout<<"banyak caranya "<<kali<<endl;*/
	ans+=kali;
}
void buatsequence(int digit,int depth,LL target){
	//cout<<depth<<" "<<((digit>>1)+1)<<endl;
	if(depth==(digit>>1)+1)			//karena 1 base index
	{
		if(digit&1)
		{
			arr[depth]=0;
			ukuranarr=depth;
		}
		else
			ukuranarr=depth-1;
		
		if(target==0)
			hitungans();
		return;
	}
	LL pengali=pangkat[digit-(depth-1)-1]-pangkat[depth-1];
	//cout<<"pengali dari "<<digit<<" pada "<<depth<<" "<<pengali<<endl;
	int a=-10,b=-9;
	for(int i=-9;i<=9;i++)
	{
		if(pengali*LL(i)>=target)
			break;
		a++;b++;
	}
	
	if(a>=-9)
	{
		arr[depth]=a;
		buatsequence(digit,depth+1,target-pengali*LL(a));
	}
	if(b<=9)
	{
		arr[depth]=b;
		buatsequence(digit,depth+1,target-pengali*LL(b));
	}
}
int main()
{
	cin>>d;
	isisimpan();
	isipangkat();
	/*for(int i=-9;i<=9;i++)
		cout<<"banyak caranya dari "<<i<<" "<<banyakcara(i)<<endl;*/
	int digit=totaldigit(d);
	for(int i=digit;i<=2*digit;i++)
	{
		//cout<<"buat dengan banyak digit "<<i<<endl;
		buatsequence(i,1,d);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n = ni()
P = list(ma())
cnt = 0
for i in range(1,n-1):
    if P[i] >min(P[i-1],P[i+1]) and P[i] <max(P[i-1],P[i+1]):
        cnt+=1
print(cnt)


Measured memory_bytes: 9396
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int long long
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pll pair<ll,ll> 
#define N 100000
#define double long double
int gcd(int a,int b)
{
if(a%b==0)
     return b;
     else
          return gcd(b,a%b);
}

int32_t main()
{
	IOS;
	/*#ifndef ONLINE_JUDGE
	freopen("int.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif*/
	int n;
	cin>>n;
	int px=0;
	int py=0;
	int pt=0;
	bool ch=1;
	for(int i=0;i<n;i++)
	{
		int t,x,y;
		cin>>t>>x>>y;
		int diff=t-pt;
		int mov=abs(px-x)+abs(py-y);
		//trace2(diff,mov);
		if((diff-mov)%2 || diff-mov<0)
			ch=0;
		pt=t;
		px=x;
		py=y;
	}
	if(ch)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()

twice = list(filter(lambda x:x%4==2, a))
quad = list(filter(lambda x:x%4==0, a))

if len(quad) >= n//2:
    print("Yes")
elif len(twice) + 2*len(quad) >= n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A[N][N];
    REP(i,N) REP(j,N-1){
        cin >> A[i][j];
        A[i][j]--;
    }
    bool flag = 0;
    int maxv = 0,cnt = 0;
    bool used[N] = {};
    int yoko[N] = {};
    REP(k,(N*(N-1)/2)+1){
        flag = 0;

    REP(i,N){
      	if(yoko[i] >= N-1) continue;
        int M = A[i][yoko[i]];
        if(i == A[M][yoko[M]]){

            if(!used[i] && !used[M]){
                yoko[i]++;
                yoko[M]++;
                used[i] = 1;
                used[M] = 1;
                maxv += 2;
              	flag = 1;
                if(maxv == N*(N-1)){
                  	cnt++;
                    cout << cnt << endl;
                    return 0;
                }
            }
          
        }
        else if(i == N-1 && !flag){
            cout << -1 << endl;
            return 0;
        }
    }
    cnt++;
    REP(i,N) used[i] = 0;
    }
}

Measured memory_bytes: 4224
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - i;
        }
        Arrays.sort(a);
        int mid;
        if (n % 2 == 1) {
            mid = a[(n - 1) / 2];
        } else {
            mid = (a[n / 2] + a[n / 2 - 1]) / 2;
        }
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += Math.abs(a[i] - mid);
        }
        System.out.println(sum);
    }
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--)
    {
        string s,t; cin >> s >> t;
        if(t.find(s) == 0) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}


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

using namespace std;
using ll =long long;
using db = double;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;

ll ans;
//ここから書き始める
int main()
{
	cout << setprecision(10);
	ll n ;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];

	ll ans = 0;
	ll m =1e9+1;
	//絶対値が一番小さい物を保持しておく、それを負にして他は正
	rep(i,n){
		chmin(m,abs(v[i]));
	}
	//マイナスの数を数える
	ll count = 0;
	rep(i,n){
		if(v[i]<0){
			count ++ ;
		}
	}
	if (count % 2 ==0){
		rep(i,n){
			ans += abs(v[i]);
		}
	}else{
		rep(i,n){
			ans+=abs(v[i]);
		}
		ans -= 2 * m;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i=0; i<n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};


int main(){
    int a,b,q; cin >> a >> b >> q;
    vector<long long> s(a+2),t(b+2),ans(q);
    s[0] = -1e15,s[a+1] = 1e15;
    t[0] = -1e15,t[b+1] = 1e15;
    for (int i = 1; i <= a; i++) cin >> s[i];
    for (int i = 1; i <= b; i++) cin >> t[i];

    //cout << "--------------" << endl;

    for (int i = 0; i < q; i++){
        long long x; cin >> x;
        int s2 = upper_bound(s.begin(), s.end(), x) - s.begin();
        int s1 = s2 - 1;
        int t2 = upper_bound(t.begin(), t.end(), x) - t.begin();
        int t1 = t2 - 1;   
        long long mn = 1e15;
        mn = min(mn, max(s[s2],t[t2]) - x);
        mn = min(mn, min(s[s2] - x + abs(s[s2]-t[t1]), abs(s[s2]-t[t1]) + x - t[t1]));
        mn = min(mn, min(t[t2]-x + abs(t[t2]-s[s1]) , x-s[s1] + abs(t[t2]-s[s1])));
        mn = min(mn, x - min(s[s1],t[t1]));
        ans[i] = mn;
    }

    //cout << "--------------" << endl;
    for (auto i : ans){
        cout << i << endl;
    }
        
}

Measured memory_bytes: 3712
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <sstream>
#include <cstdlib>
typedef long long  ll;
using namespace std;
int main()
{
	int N;
	cin >> N;
	int a[N];
	ll ans=0;
	for(int i=0; i<N;i++){
		cin >>a[i];
		ans+=a[i]-1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
double a[6],d,r,s;main(i){for(;~scanf("%lf",a-i--%6);!i|i%6||puts(d>r+s?"0":r>d+s?"2":s>d+r?"-2":"1",d=hypot(*a-a[3],a[1]-a[4])))r=a[2],s=a[5];}

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

int main() {
int64_t A, B,N;
cin >> N>>A>>B;
int64_t d = N/(A+B);
if(A==0)
{
  cout << 0 <<endl;
  return 0;
}
if(N%(A+B) > A ) cout << d*A + A << endl;
else cout << d*A +N%(A+B) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  if (abs(a - b) % 2 == 1)
  {
    cout << "Borys" << endl;
  }
  else
  {
    cout << "Alice" << endl;
  }
}


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

int main() {
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'A') {
			a = i;
			break;
		}
	}for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'Z') {
			b = i;
		}
	}
	std::cout << b - a + 1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int a[100001],grp[100001];

int main()
{
	int		i,j,n,ans;
	
	scanf("%d", &n);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);

	ans = 1;
	grp[ans] = a[1];
	if (n>1) {
		for(i=2;i<=n;i++) {
			if (grp[ans] >= a[i]) {
				grp[++ans] = a[i];
			} else {
				for(j=1;j<=ans;j++) {
					if (grp[j]<a[i]) {
						grp[j] = a[i];
						break;
					}
				}
			}
		}
	}

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


	return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3
import sys
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))

def main():
    sys.setrecursionlimit(10**8)
    INF = float("inf")

    a = INT()
    print(a + a**2 + a**3)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
x = int(input())
if 400<=x<=599:
    print(8)
elif 600<=x<=799:
    print(7)
elif 800<=x<=999:
    print(6)
elif 1000<=x<=1199:
    print(5)
elif 1200<=x<=1399:
    print(4)
elif 1400<=x<=1599:
    print(3)
elif 1600<=x<=1799:
    print(2)
elif 1800<=x<=1999:
    print(1)

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int m,d,cnt=0,a,b;
   cin>>m>>d;

   rep(i,10,d+1){
      a = i % 10;
      b = i / 10;
      if(a >= 2 && b >= 2 && a*b <= m) ++cnt;
   }

   cout<<cnt<<'\n';
}

Measured memory_bytes: 256
//
//  main.cpp

#include <iostream>
using namespace std;

long long max(long long x,long long y){
	if(x > y){
		return x;
	}else{
		return y;
	}
}

int main(){
	while(1){
		int n,k;
		long long array[100001]={};
		long long total[100001]={};
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		for(int i=0;i<n;i++){
			cin >> array[i];
		}
		long long x=0;
		for(int i=0;i<k;i++){
			x += array[i];
		}
		total[0] = x;
		for(int i=1;i<=n-k;i++){
			total[i] = total[i-1] - array[i-1] + array[i+k - 1];
		}
		long long answer = -10000000000;
		for(int i=0;i<100001;i++){
			answer = max(answer,total[i]);
		}
		cout << answer << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define N 305
using namespace std;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,a[N][N],vis[N],cnt[N];
int main() {
	n = rd(), m = rd();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) a[i][j] = rd();
	for (int i=1;i<=m;i++) vis[i] = 1;
	int ans = n;
	for (int _=1;_<=m;_++) {
		memset(cnt,0,sizeof(cnt));
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				if (vis[ a[i][j] ]) {
					cnt[ a[i][j] ]++;
					break;
				}
		int mx = 0, id = 0;
		for (int i=1;i<=m;i++)
			if (cnt[i] >= mx)
				mx = cnt[i], id = i;
		ans = min(ans, mx);
		vis[id] = 0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()

const int N = 8;
const int inf = (1<<20);
char m[N][N];

inline int getval(int c,int j,int bit){
  if      (j == -1)j=0;
  else if (j ==  c)j=c-1;
  return (bit&(1<<j)) != 0;
}

inline int checkij(int r,int c,int i,int j,int bit0,int bit1,int bit2){
  int ret=0;
  int bit=0;
  //bit0
  if (i-1 < 0)bit=bit1;
  else        bit=bit0;
  REP(k,-1,2)ret+=getval(c,j+k,bit);

  //bit1
  bit=bit1;
  REP(k,-1,2)ret+=getval(c,j+k,bit);

  //bit2
  if (i+1 == r)bit=bit1;
  else         bit=bit2;
  REP(k,-1,2)ret+=getval(c,j+k,bit);
  return ret;
}

inline bool isvalid(int r,int c,int now,int bit0,int bit1,int bit2){
  rep(j,c){
    int cnt=checkij(r,c,now-1,j,bit0,bit1,bit2);
    if ((m[now-1][j] == '#'&&cnt>=5) ||
	(m[now-1][j] == '.'&&cnt<5 ));
    else return false;
  }
  return true;
}

int dp[1<<N][1<<N][N];
int dp2[1<<N][1<<N][N];
//int bitcount[1<<N];
#define bitcount(i) (__builtin_popcount(i))

void solve(int r,int c,int bit0,int bit1,int now){
  if (now == r){
    if (isvalid(r,c,now,bit0,bit1,0)){
      dp[ bit0][bit1][now-1]=bitcount(bit1);
      dp2[bit0][bit1][now-1]=bitcount(bit1);
    }else {
      dp[ bit0][bit1][now-1] =-inf;
      dp2[bit0][bit1][now-1]= inf;
    }
    return;
  }
  int &ret= dp[ bit0][bit1][now-1];
  int &ret2=dp2[bit0][bit1][now-1];
  if (ret == -2*inf ){
    ret=-inf;
    ret2=inf;
    rep(i,(1<<c)){
      if (isvalid(r,c,now,bit0,bit1,i)){
	solve(r,c,bit1,i,now+1);
	if (dp[bit1][i][now] != -inf){
	  ret =max(ret, dp[bit1][i][now]+bitcount(bit1));
	  ret2=min(ret2,dp2[bit1][i][now]+bitcount(bit1));
	}
      }
    }
  }
  return;
}

main(){
  //rep(i,(1<<N))bitcount[i]=__builtin_popcount(i);
  int c,r,tc=1;
  while(cin>>c>>r && r){
    cout <<"Case " << tc++ << ": ";
    rep(i,r)cin>>m[i];
    rep(i,(1<<c)){
      rep(j,(1<<c)){
	rep(k,r){
	  dp[i][j][k]=-2*inf;
	  //dp2[i][j][k]=2*inf;
	}
      }
    }
    int maxi=-2*inf,mini=inf;
    rep(i,(1<<c)){
      solve(r,c,0,i,1);
      if (dp[0][i][0] >= 0){
	maxi=max(maxi,dp[0][i][0]);
	mini=min(mini,dp2[0][i][0]);
      }
    }

    if (maxi < 0){
      cout <<"Impossible" << endl;
      continue;
    }else  cout << maxi-mini << endl;
  }
  return false;
}



/*
void test(){
  int bit0=17,bit1=14,bit2=24;
  int r=3,c=5;
  rep(j,c)cout << checkij(r,c,0,j,0,bit0,bit1)<<" ";cout << endl;
  rep(j,c)cout << checkij(r,c,1,j,bit0,bit1,bit2)<<" ";cout << endl;
  rep(j,c)cout << checkij(r,c,2,j,bit1,bit2,0)<<" ";cout << endl;
}

void output(int c,int bit){
  rep(j,c){
    if ((1<<j)&bit) cout <<"#";
    else cout << ".";
  }
  cout << endl;
}

*/

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

int main()
{
    int a, b;
    cin >> a >> b;

    if(a <= 8 && b <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define hell                         1000000007 
    #define M                            1000000007
    #define Maxi                      10000000000000000
        #define lcm(a,b)                     (a*b)/__gcd(a,b)
        #define ll                           long long

        #define vll                          vector<ll>
        #define vi                           vector<long long>
        #define pll                          vector< pair<ll,ll> >
        #define pb                           push_back
        //#define mp                           make_pair
        #define all(v)                       v.begin(),v.end()
        #define lbnd                         lower_bound
        #define ubnd                         upper_bound
        #define bs                           binary_search
        #define F                            first
        #define S                            second
        #define rep(i,a,b)                   for(i=a;i<b;i++)
        #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
        #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
        #define ret(x)                       return cout<<x,0;
        #define dbg(x)                       cout << #x << " is " << x << endl;
        //#define endl                           '\n'
     
     
        // Debug //
     
        #define trace(x)                 cerr << #x << ": " << x << endl;
        #define trace1(x)                cerr << #x << ": " << x << endl;
        #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
        #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
        #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
        #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
        #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;


    using namespace std;
    
    int main()
    {

          ios_base::sync_with_stdio(false);
          cin.tie(NULL);cout.tie(NULL);
        
          

           ll a,b;
           cin>>a>>b;
           cout<<max(a+b,max(a-b,a*b));

          return 0;


  }

  

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task "photo"

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int N, M, V, P;
int a[maxn];

bool check(int val)
{
    if (a[val] + M < a[P]) return false;
    ll cnt = 0;
    for (int i=1; i<=N; ++i){
        if (i < P || i >= val){
            cnt += M;
        }
        else{
            cnt += min(a[val]  + M - a[i], M);
        }
    }
    return cnt >= 1ll * M * V;
}

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".in", "r")){
        freopen(Task".in", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> N >> M >> V >> P;
    for (int i=1; i<=N; ++i){
        cin >> a[i];
    }
    sort(a+1, a+1+N, greater<int>());
    int l=1, r=N, mid;
    while (l <= r){
        mid = (l + r) / 2;
        if (check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    cout << r << '\n';
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
const int N = 100005;
int n;
int a[N], b[N], c[N], x, y, z;
int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x >> y >> z;
		a[i] = x + max(b[i - 1], c[i - 1]);
		b[i] = y + max(a[i - 1], c[i - 1]);
		c[i] = z + max(a[i - 1], b[i - 1]);

	}
	cout << max(max(a[n], b[n]), c[n]);
}


Measured memory_bytes: 1408
N,A,B=map(int,input().split())
Z=[]
for n in range(1,N+1):
    ns=str(n)
    len_ns=len(ns)
    total=0
    for x in range(len_ns):
        total=total+int(ns[x])
    if A<=total<=B:
        Z.append(n)
print(sum(Z))

Measured memory_bytes: 3292
from collections import deque
h,w=map(int,input().split())
queue=deque()
s=[list(input()) for _ in range(h)]
seen=[[False]*w for _ in range(h)]
queue.append([0,0])
ans=[[1000000000]*w for _ in range(h)]
seen[0][0]=True
ans[0][0]=1
for i in range(h*w*10):
    if len(queue)==0:
        break
    cnt=queue.popleft()
    if cnt[0]!=0:
        if seen[cnt[0]-1][cnt[1]]==False and s[cnt[0]-1][cnt[1]]==".":
            queue.append([cnt[0]-1,cnt[1]])
            ans[cnt[0]-1][cnt[1]]=ans[cnt[0]][cnt[1]]+1
            seen[cnt[0]-1][cnt[1]]=True
    if cnt[1]!=0:
        if seen[cnt[0]][cnt[1]-1]==False and s[cnt[0]][cnt[1]-1]==".":
            queue.append([cnt[0],cnt[1]-1])
            ans[cnt[0]][cnt[1]-1]=ans[cnt[0]][cnt[1]]+1
            seen[cnt[0]][cnt[1]-1]=True
    if cnt[0]!=h-1:
        if seen[cnt[0]+1][cnt[1]]==False and s[cnt[0]+1][cnt[1]]==".":
            queue.append([cnt[0]+1,cnt[1]])
            ans[cnt[0]+1][cnt[1]]=ans[cnt[0]][cnt[1]]+1
            seen[cnt[0]+1][cnt[1]]=True
    if cnt[1]!=w-1:
        if seen[cnt[0]][cnt[1]+1]==False and s[cnt[0]][cnt[1]+1]==".":
            queue.append([cnt[0],cnt[1]+1])
            ans[cnt[0]][cnt[1]+1]=ans[cnt[0]][cnt[1]]+1
            seen[cnt[0]][cnt[1]+1]=True
cnt2=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt2+=1
if seen[-1][-1]==False:
    print(-1)
else:
    print(cnt2-ans[-1][-1])


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

int main(){
   ll n,k;
   cin >> n >> k;
   vector<ll> p(n);
   rep(i,n) cin >> p[i];
   ll ans=0;
   sort(p.begin(), p.end());
   rep(i,k){
       ans += p[i];
   }
   cout<< ans << endl;
   return 0;
}

Measured memory_bytes: 3636
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let vec : Vec<&str> = line.split_whitespace().collect();

    let a : i64 = vec[0].parse().unwrap_or(0); // 入力は整数

    let b : f64 = vec[1].parse().unwrap_or(0.0); // 入力値は小数

    let ib : i64 = (b * 100.0 + 0.5) as i64;

    let result : i64 = (a * ib) / 100;

    println!("{}", result);
}

Measured memory_bytes: 2172
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 300005
int n, m, a[maxn], Ans, inv, ton[maxn];
il int mul(int a, int b) {
	return a * b % mod;
}
il int inc(int a, int b) {
	a += b;
	if(a >= mod) a -= mod;
	return a;
}
signed main() {
	n = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 0, 61) {
		ton[0] = ton[1] = 0;
		int sum = 0;
		drep(j, 1, n) ton[(a[j] >> i) & 1] ++, Ans = inc(Ans, mul((1ll << i) % mod, ton[((a[j] >> i) & 1) ^ 1]));
	}
	cout << Ans % mod ;
	return 0;
}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 100005;
int n;
vector<int>g[N];
int pr[N];


int find(int r)
{
    if(pr[r] == r)return r;
    else return pr[r] = find(pr[r]);
}
struct edge{
    int u,v,w;
    bool operator < ( const edge &p ) const {
        return w < p.w;
    }
};

int main()
{
    cin >> n;
    vector<pii>X,Y;
    FOR(i,1,n)
    {
        int a,b;
        cin >> a >> b;
        X.push_back(mk(a,i));
        Y.push_back(mk(b,i));
    }
    SORT(X);
    SORT(Y);
    vector<edge>e;
    for(int i = 1;i < X.size();i++){
        int u = X[i - 1].second;
        int v = X[i].second;
        int w = X[i].first - X[i - 1].first;
        e.push_back({u,v,w});
    }
    for(int i = 1;i < Y.size();i++){
        int u = Y[i - 1].second;
        int v = Y[i].second;
        int w = Y[i].first - Y[i - 1].first;
        e.push_back({u,v,w});
    }
    sort(e.begin(),e.end());
    FOR(i,1,n)pr[i] = i;
    LL s = 0;
    for(int i = 0;i < e.size();i++){
        int u = find(e[i].u);
        int v = find(e[i].v);
        if(u == v)continue;
        pr[v] = u;
        s = s + e[i].w;
    }
    cout << s << "\n";
}



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

int main()
{
	int n,x,t;
	cin>>n>>x>>t;
	int d=n/x;
	int r=n%x;
	if(r==0)
	{
		cout<<t*d;
	}
	else
	{
		cout<<t*(d+1);
	}
}

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

int main() {
  string S;
  cin >> S;
  
  vector<bool> dict(26, false);
  
  sort(S.begin(), S.end());
  
  for (int i = 0; i < S.size(); ++i) {
    int idx = S.at(i) - 'a';
    dict.at(idx) = true;  
  }
  
  bool found = false;
  for (int i = 0; i < 26; ++i) {
    if (dict.at(i) == false) {
      char ch = 'a' + i;
      cout << ch << endl;
      found = true;
      break;
    }
  }
  if (!found) cout << "None" << endl;
  
}

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

int main() {
  ll n,count=0;
  cin >> n;
  vector<ll> a(n,0),b(n,0);
  r(i,n)cin >> a[i]>>b[i];
  for(ll i=n-1;i>=0;i--){
    count+=(b[i]-(a[i]+count)%b[i])%b[i];
  }
  cout << count<<endl;
}


Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, q = map(int, input().split())
    cnt = [[0] * n for _ in range(n)]
    for _ in range(m):
        l, r = map(int, input().split())
        cnt[l - 1][r - 1] += 1

    R = [[0] * (n + 1) for _ in range(n + 1)]
    for h in range(n):
        for w in range(n):
            R[h + 1][w + 1] = R[h][w + 1] + R[h + 1][w] - R[h][w] + cnt[h][w]

    for _ in range(q):
        p, q = map(int, input().split())
        res = R[q][q] - R[p - 1][q] - R[q][p - 1] + R[p - 1][p - 1]
        print(res)


if __name__ == '__main__':
    resolve()


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

int main()
{
    int n;
    ll out=0;

    cin >> n;

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

        if (!(i%3==0 || i%5==0))out+=i;

    }

    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

struct edge{
	int from,to,cost;
	edge(int a,int b,int c){from = a , to = b , cost = c;} 
};

int m,n,k,dd;
vector<edge> es;
const int INF=100000;
int d[1<<6][109];
int cake[9];

int root(string s){
	if(s[0]=='H')return 0;
	if(s[0]=='D')return 1;
	string num = s.substr(1,s.size()-1); 
	if(s[0]=='C')return 1+atoi(num.c_str());
	if(s[0]=='L')return m+1+atoi(num.c_str());
}

void path(int s){
	int a,b;
	rep(b,1<<m)for(a=0;a<109;a++)d[b][a]=INF;
	d[0][s]=0;
	while(true){
		bool upd=false;
		for(a=0;a<es.size();a++){
			edge e=es[a];
			rep(b,1<<m){
				if(e.to>1 && e.to<=1+m && (b & (1<<(e.to-2))) ) continue;
				if(e.to>1 && e.to<=1+m){
					if(d[b|(1<<(e.to-2))][e.to]>d[b][e.from]+e.cost-cake[e.to-2]){
						d[b|(1<<(e.to-2))][e.to]=d[b][e.from]+e.cost-cake[e.to-2];
						upd=true;
					}
				}else if(d[b][e.to]>d[b][e.from]+e.cost){
					d[b][e.to]=d[b][e.from]+e.cost;
					upd=true;
				}
			}
		}
		if(!upd)break;
	}
}

int main(void){
	int a;
	while(1){
		int ans=INF;
		cin >> m >> n >> k >> dd;
		if(m==0 && n==0 && k==0 && dd==0)break;
		es.clear();
		for(a=0;a<m;a++){
			cin >> cake[a];
		}
		for(a=0;a<dd*2;a+=2){
			int b,c,dd;
			string s;
			string ss;
			cin >> s >> ss >> dd;
			b=root(s);
			c=root(ss);
			es.push_back(edge(b,c,dd*k));
			es.push_back(edge(c,b,dd*k));
		}
		path(0);
		rep(a,1<<m)ans=min(ans,d[a][1]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 976
#include<stdio.h>
main(){
  int a=0;
  int W,H,x,y,r=0;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r>=0&&x+r<=W){
    if(y-r>=0&&y+r<=H){
      a=1;
    }
  }
  else{
    a=0;
  }
  if(a==1){
    printf("Yes\n");
  }
  else if(a==0){
    printf("No\n");
  }
  return 0;
}
 

Measured memory_bytes: 584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

bool perfect(int s)
{
	int k=sqrt(s);
	return k*k == s;
}

int main()
{
	// cout<<perfect(4);
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.length() <= k)
		cout<<s;
	else
		cout<<(s.substr(0,k) + "...");
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

const ll mod = 1e9+7;

int main(){
  ll n, k;  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n+1; ++i){
    ll temp = (n+1)*(n+2)/2 - (n+1-i)*(n+2-i)/2 - i*(i+1)/2 + 1;
    ans += temp;
    ans %= mod;  
  }
  cout << (ans+mod)%mod << endl;
  return 0;
}

Measured memory_bytes: 3636
def io_tmp():
    global input
    import io
    f = io.StringIO(open(0).read())
    input = f.readline

io_tmp()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1, t-1] = graph[t-1, s-1] = w
dist = floyd_warshall(graph, directed=False)
graph = np.ones((N, N))
np.fill_diagonal(graph, 0)
graph[dist > L] = 0
dist = floyd_warshall(graph, directed=False)
dist[np.isinf(dist)] = 0
dist = dist.astype(int)

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(dist[s-1][t-1] - 1)
print(*ans, sep='\n')


Measured memory_bytes: 26940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1] -= ('A'-'a');
    cout<<s<<endl;
}


Measured memory_bytes: 764
def larger(x, y):
	if x > y: return x
	return y
def smaller(x, y):
	if x < y: return x
	return y

N, M = map(int, raw_input().split())
L = 1
R = N
flag = True
for i in range(0, M):
	lft, rgt = map(int, raw_input().split())
	if R < lft or rgt < L:
		flag = False
		break
	L = larger(L, lft)
	R = smaller(R, rgt)
if flag: print R-L+1
else: print 0

Measured memory_bytes: 5764
#include <bits/stdc++.h>
using  namespace std;
int main(){
    string s;
    int a, b, c, d, ans;
    char op1, op2, op3;
    cin >> s;
    a = int(s[0])-48;
    b = int(s[1])-48;
    c = int(s[2])-48;
    d = int(s[3])-48;

    for(int i=0;i<1<<4;i++){
        ans = a;

        if(i&(1<<1)){
            ans += b;
            op1 = '+';
        }else{
            ans -= b;
            op1 = '-';
        }
        if(i&(1<<2)){
            ans += c;
            op2 = '+';
        }else{
            ans -= c;
            op2 = '-';
        }
        if(i&(1<<3)){
            ans += d;
            op3 = '+';
        }else{
            ans -= d;
            op3 = '-';
        }
        if(ans == 7){
            break;
        }
     
    }

    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int H, W;
	cin >> H >> W;
	vec<string> MAP;
	REP(i, H) {
		string S;
		cin >> S;
		MAP.push_back(S);
	}
	vec<int> Ai, Aj;
	REP(i, H) {
		bool b = false;
		REP(j, W) {
			if (MAP[i][j] == '#') {
				b = true;
			}
		}
		if (!b) {
			Ai.push_back(i);
		}
	}
	REP(j, W) {
		bool b = false;
		REP(i, H) {
			if (MAP[i][j] == '#') {
				b = true;
			}
		}
		if (!b) {
			Aj.push_back(j);
		}
	}

	REP(i, H) {
		bool b1 = false;
		REP(ii, Ai.size()) {
			if (i == Ai[ii]) {
				b1 = true;
			}
		}
		if (b1)continue;
		
		REP(j, W) {
			bool b2 = false;
			REP(jj, Aj.size()) {
				if (j == Aj[jj]) {
					b2 = true;
				}
			}
			if (b2)continue;
			cout << MAP[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#解説通り
N,M,K = map(int,input().split())
m = 998244353
ans = (M*pow(M-1,N-1,m))%m #すべて違う色,k=0
alpha = 1#n-1Ck, k=0の値で初期化
for k in range(1,K+1):
    alpha = (alpha*(N-k)*pow(k,m-2,m))%m#逆元で計算しないとTLE
    ans = (ans + M*alpha*pow(M-1,N-k-1,m))%m
print(ans)


Measured memory_bytes: 9128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

const int MaxN = 1e5;
using namespace std;
int a, b, c, d, e, f;
int main()
{
	while(~scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f)){
		int ansa = 0, ansb = 0;
		int water = 0, sugar = 0, cnt = 0;
		for(int i  = 0; i * a * 100 <= f; i++){
			for(int j = 0; j * b * 100 <= f; j++){
				if(i == 0 && j == 0) continue;
				if((i*a + j*b) * 100 > f) break;
				for(int k = 0; ; k++){
					if((i*a + j*b) * 100 + k * c > f) break;
					for(int l = 0; ; l++){
						int tempa = (i*a + j*b) * 100; 
						int tempb = c * k + d * l;
						int cnt = (i*a + j*b) * e;
						if(tempa + tempb > f) break;
						if(tempb <= cnt){
							if(ansa == 0 && ansb == 0){
								ansa = tempa, ansb = tempb;
							}
							else if(1.0 * tempb / (tempa + tempb) > 1.0 * ansb / (ansa + ansb)){
								ansa = tempa, ansb = tempb;
							}
						}
					}
				}
			}
		}
		printf("%d %d\n", ansa + ansb, ansb);
	}
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi s(m), c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    vi q(n, -1);
    rep(i, m) {
        if (q[s[i]]!=-1 && q[s[i]]!=c[i]) {
            cout << -1 << endl;
            return 0;
        }
        else q[s[i]] = c[i];
    }
    if (n>1 && q[0]==0) {
        cout << -1 << endl;
        return 0;
    }
    int b = 1, e = 10;
    rep(i, n-1) {
        b *= 10; e *= 10;
    }
    if (n == 1) b = 0;
    for (int i=b; i<e; ++i) {
        int i2 = i;
        bool ok = true;
        repr(j, n) {
            if (q[j]!=-1 && i2%10!=q[j]) ok = false;
            i2 /= 10;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define lll pair<ll,ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vi vector<int>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define ppb() pop_back()
#define mkp(a,b) make_pair(a,b)
#define vs vector<string>
#define vc vector<char>
#define deb1(a) cout<<#a<<" "<<a<<"\n"
#define deb2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n"
#define mms0(a) memset(a,0,sizeof(a))
#define mms1(a) memset(a,-1,sizeof(a))
#define FOR(a,b,c) for(int i=(a);i<(b);i+=(c))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define _ 0
using namespace std;




void solve(){
   int N,K;
   cin>>N>>K;
   int arr[N+1];
   FOR(1,N+1,1) cin>>arr[i];
   ll inf  = (ll)(1e16);
   vector<ll> dp(N+1,inf);
   for(int i=1;i<=min(K,N);i++){
      dp[i] = abs(arr[i] - arr[1]);
   }
   for(int i=K+1;i<=N;i++){
      ll nim = inf;
      for(int j=i-K;j<i;j++){
         nim = min(nim,dp[j] + abs(arr[j] - arr[i]));
      }
      dp[i] = nim; 
   }

  // for(int i=0;i<=N;i++) cout<<dp[i]<<" ";cout<<"\n";
   cout<<dp[N];
}




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

Measured memory_bytes: 4568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//提示されるダイス目の入力
		String dice = sc.nextLine();

		//入力されたダイス目の配列
		String[] dicenum = dice.split(" ");
		int[] dicenumber = new int[6];

		for (int i = 0; i < dicenum.length; i++) {
			dicenumber[i] = Integer.parseInt(dicenum[i]);
		}

		//質問の数ｑ
		int question = sc.nextInt();

		for (int i = 0; i < question; i++) {

			//指定されたダイス目(上)
			int dicetop = sc.nextInt();

			//指定されたダイス目(前)
			int dicefront = sc.nextInt();

			//Diceクラスの呼び出し
			Dice diceClass = new Dice(dicenumber);

			//Rollクラスの呼び出し
			Roll diceRoll = new Roll();

			//Diceクラスの受け渡し
			diceRoll.setDice(diceClass);

			//Rollクラスに上面と前面を渡して結果を受け取りint型に格納
			int diceanswer = diceRoll.roll(dicetop, dicefront);

			System.out.println(diceanswer);
		}
		sc.close();

	}

}

class Roll {

	Dice dice;

	public void setDice(Dice getDice) {
		this.dice = getDice;
	}

	//呼び出し元からint型のdicetopとdicefrontを受け取る
	public int roll(int dicetop, int dicefront) {

		//番地の目の移動
		//1,2,3,4,5,6
		//移動方向がN・Sの時は3と4は変わらない
		//移動方向がE・Wの時は2と5は変わらない
		//1と6は常に移動する

		//Sの時は1⇒2⇒6⇒5⇒1の位置にそれぞれ移動する
		//Nの時は1⇒5⇒6⇒2⇒1の位置にそれぞれ移動する
		//Eの時は1⇒3⇒6⇒4⇒1の位置にそれぞれ移動する
		//Wの時は1⇒4⇒6⇒3⇒1の位置にそれぞれ移動する

		//1-6を配列番号0-5に割り当てて並べ替えをする

		int empty = 0;

		//方向ごとに場合分け

		while (true) {

			// if文で面の番地に指定の数字が入るまで繰り返し
			if (dice.d[0] != dicetop) {

				empty = dice.d[0];
				dice.d[0] = dice.d[1];
				dice.d[1] = dice.d[5];
				dice.d[5] = dice.d[4];
				dice.d[4] = empty;

			}  if (dice.d[0] != dicetop) {

				empty = dice.d[0];
				dice.d[0] = dice.d[2];
				dice.d[2] = dice.d[5];
				dice.d[5] = dice.d[3];
				dice.d[3] = empty;

			} else if (dice.d[1] != dicefront) {
				empty = dice.d[1];
				dice.d[1] = dice.d[2];
				dice.d[2] = dice.d[4];
				dice.d[4] = dice.d[3];
				dice.d[3] = empty;
			} else {
				break;
			}

		}

		return dice.d[2];
	}
}

class Dice {

	int[] d = new int[6];

	public Dice(int[] setd) {

		this.d[0] = setd[0];
		this.d[1] = setd[1];
		this.d[2] = setd[2];
		this.d[3] = setd[3];
		this.d[4] = setd[4];
		this.d[5] = setd[5];

	}

}



Measured memory_bytes: 26036
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  
  cin >> a >> b >> c;

  int result3 = std::max({a, b, c});
  
  if (a%3 == 0) anss = "Possible";
  else if (b%3 == 0) anss = "Possible";
  else if ((a+b)%3 == 0) anss = "Possible";
  else anss = "Impossible";
  
  cout << anss << endl;

}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
s = [list(input()) for _ in range(n)]
for i in range(n):
    s[i].sort()
    s[i] = ''.join(s[i])
counter = Counter(s)
ans = 0
for val in counter.values():
    ans += val * (val - 1) // 2
print(ans)


Measured memory_bytes: 31948