akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // ver2.3.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r;  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  Vi a(n);
  Vin(a);
  
  reverse(ALL(a));
  
  if(a[0]!=2){cout << -1 << endl;return 0;}
  
  int L=2,R=3;
  int Lnew,Rnew;
  
  rep(i,1,n){
    L = dem(L,a[i]) * a[i];
    R = (R-(R%a[i])) + a[i]-1;
    //cerr << L _ R << endl;
  }
  if(L<=R) cout << L _ R << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    long long int a,b,k;
    cin>>a>>b>>k;
    if(k>=a+b){
        cout<<0<<" "<<0<<endl;
    }else if(k>a){
        cout<<0<<" "<<b-k+a<<endl;
    }else{
        cout<<a-k<<" "<<b<<endl;
    }
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var SPList = Enumerable.Range(0, N).Select(_ => Console.ReadLine().Split(' '));

            var sorted = SPList
                .Select((SP, i) => new { SP, i = i + 1 })
                .OrderBy(a => a.SP[0])
                .ThenByDescending(a => int.Parse(a.SP[1]));

            foreach (var e in sorted)
            {
                Console.WriteLine(e.i);
            }
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 11740
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,a,b,c;

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

		for(int i = 0; i < n; i++){
			scanf("%d %d %d",&a,&b,&c);
			if(a == 100 || b == 100 || c == 100 || a + b >= 180 || a+b+c >= 240){
				printf("A\n");
			}else if((a + b + c >= 210) || (a+b+c>=150 && (a >= 80 || b >= 80))){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}

	}
    return 0;
}


Measured memory_bytes: 2544
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n; cin >> n;

  if(n < 1200) cout << "ABC";
  else if(n <2800 ) cout << "ARC";
  else cout << "AGC";

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b int
    fmt.Scan(&a,&b)
    ans := a
    if a>b{
        ans--
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {

	int h;
	int w;
	cin >> h;
	cin >> w;

	char a[9][9];
	int i, j;
	int count1 = 0;
	int count2 = 0;
	for (i = 0; i < h+1; i++) {
		for (j = 0; j < w+1; j++) {
			a[i][j]='.';
		}
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	i = 0;
	j = 0;
	while ((i < h) && (j < w)){
		if (a[i+1][j] == '#') {
			a[i][j] = '.';
			i++;
		}
		else if (a[i][j + 1] == '#') {
			a[i][j] = '.';
			j++;
		}
		else {
			break;
		}
	} 
	a[i][j] = '.';
	if ((i >= h - 1) && (j >= w - 1)) {
		for (count1 = 0; count1 < h; count1++) {
			for (count2 = 0; count2 < w; count2++) {
				if (a[count1][count2] == '#') {
					cout << "Impossible";
					return 0;
				}
			}
		}
		cout << "Possible";
		return 0;
	}
	else {
		cout << "Impossible";
		return 0;
	}
		

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstdlib>
#include<iostream>
using namespace std;
struct node{
	int p,c;
}a[15];
int n,g,ans=1<<28;
int main()
{
	scanf("%d %d",&n,&g);
	for(int i=0;i<n;i++) scanf("%d %d",&a[i].p,&a[i].c);
	for(int S=0;S<1<<n;S++)
	{
		int num=0,tot=0;
		for(int i=0;i<n;i++)
			if((1<<i)&S) num+=a[i].p,tot+=(a[i].c+(i+1)*100*a[i].p);
		if(tot<g)
		{
			for(int i=n-1;i>=0;i--)
			{
				if(!((1<<i)&S))
				{
					int c=(i+1)*100,k=(g-tot)/c;
					if((g-tot)%c!=0) k++;
					if(k>=a[i].p)
					{
						num+=a[i].p,tot+=(a[i].c+(i+1)*100*a[i].p);
					}
					else
					{
						tot=g;num+=k;
					}
				}
				if(tot>=g) break;
			}
		}
		//printf("%d %d\n",num,S);
		ans=min(ans,num);
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N = 0;
long long all_sum = 0;
int a[10] {};

void dfs(int i, long long sum, long long carry) {
    // 終端条件
    if(i == N-1) {
        all_sum += carry * 10 + a[i] + sum;
        return;
    }

    // 終端でない場合
    // carryを使う
    dfs(i+1, sum + carry * 10 + a[i], 0);
    // carryを保持
    dfs(i+1, sum, carry * 10 + a[i]);
}

int main() {
    string line; cin >> line;
    N = line.length();
    for(int i = 0; i < N; ++i) {
        a[i] = line[i] - '0';
    }

    dfs(0, 0, 0);

    cout << all_sum << endl;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define forn(i , n) for(int i=0;i<n;i++)



void print(vector<int> v){
    int n = v.size();
    
    forn(i , n){
        cout << v[i] << (i != n - 1 ? ' ' : '\n' );
    }
}


void insertionsort(vector<int> v , int size){
    for(int i = 1; i < size; i++){
        int key = v[i];
        int j = i - 1;
        
        while(j >= 0 && v[j] > key){
            swap(v[j + 1] , v[j]);
            j--;
        }
        
        print(v);
    } 
}


int main(){
    int n;
    cin >> n;
    
    vector<int> v(n , 0);
    forn(i , n){
        cin >> v[i];
    }
    
    int size = v.size();
    
    
    print(v);
    insertionsort(v , size);
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

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

    int maxv = -1000000000;
    int minv = R[0];

    for(int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3868
#include <cstdio>
#include <algorithm>

using namespace std;

int a[100000];
int x[100000];
long long sum1[100001];
long long sum2[100001];

int main() {
    int n, q, i;
    
    scanf("%d %d", &n, &q);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < q; i++) scanf("%d", &x[i]);
    
    for (i = 0; i < n; i++) sum1[i + 1] = sum1[i] + a[i];
    for (i = 0; i < n; i++) {
        sum2[i + 1] = sum2[i];
        if (n % 2 != i % 2) sum2[i + 1] += a[i];
    }
    
    for (i = 0; i < q; i++) {
        int l, r, m;
        long long ans = 0;
        
        l = 1, r = n, m = (l + r) / 2;
        
        while (r - l > 1) {
            if (m * 2 > n + 1) {
                r = m;
                m = (l + r) / 2;
            } else {
                int p = a[n - m];
                int q = a[max(n - m * 2 + 1, 0)];
                
                if (abs(x[i] - p) >= abs(x[i] - q)) {
                    l = m;
                    m = (l + r) / 2;
                } else {
                    r = m;
                    m = (l + r) / 2;
                }
            }
        }
        
        ans += sum1[n] - sum1[n - l];
        if (n - l * 2 > 0) ans += sum2[n - l * 2 + 1];
        
        printf("%lld\n", ans);
    }
    
    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int i,c=0;
    cin>>s>>t;
    for(i=0; i<3; i++)
    {
        if(s[i]==t[i])
        {
            c++;

        }
    }

cout<<c<<endl;

}


Measured memory_bytes: 256
import itertools

def main():
    N = int(input())
    P = input().replace(" ", "")
    Q = input().replace(" ", "")
    vals = []
    for comb in itertools.permutations(list(map(str, range(1, N+1))), N):
        vals.append("".join(comb))
    vals.sort()
    print(abs(vals.index(P) - vals.index(Q)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76128
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m;
  cin >> n >> m;

  scc_graph g(n);
  for(ll i=0;i<m;i++){
    ll a,b;
    cin >> a >> b;
    g.add_edge(a,b);
  }

  auto ans=g.scc();
  cout << ans.size() << endl;
  for(ll i=0;i<ans.size();i++){
    cout << ans[i].size() << " ";
    for(ll j=0;j<ans[i].size();j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

}

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

namespace ConsoleApp95 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = st[0];
            int M = st[1];
            var a = new int[M];
            var b = new int[M];

            var tupleList = new List<Tuple<int, int>>();

            for (int i = 0; i < M; i++) {
                var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = x[0];
                b[i] = x[1];
                tupleList.Add(new Tuple<int, int>(a[i], b[i]));
            }

            int ans = 0;

            tupleList.Sort((p, q) => p.Item1.CompareTo(q.Item1));

            int before_cnt = 0;

            for (int i = 0; i < M; i++) {
                var already = new List<int> { };
                already.Add(tupleList[i].Item1);

                var check = Enumerable.Repeat(0, M).ToArray();

                while (true) {
                    before_cnt = already.Count();

                    for (int j = 0; j < M; j++) {
                        if (i == j) {
                            continue;
                        }

                        if (check[j] == 0 && already.Contains(tupleList[j].Item1)) {
                            already.Add(tupleList[j].Item2);
                            check[j] = 1;
                        } else if (check[j] == 0 && already.Contains(tupleList[j].Item2)) {
                            already.Add(tupleList[j].Item1);
                            check[j] = 1;
                        }
                        


                    }

                    if (before_cnt == already.Count()) {
                        break;
                    }
                }
                
                if (already.Distinct().Count() != N) {
                    ans++;
                }





            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;
string s;
unordered_set<char> ss;

int go(int i,int j,int k)
{
    ss.clear();
    ss.insert(s[i]);
    ss.insert(s[j]);
    ss.insert(s[k]);
    return ss.size()==3;
}

int main()
{
    idfc;
    int n;
    cin>>n>>s;
    ll ans=0;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
    int f=0;
    int i;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')d++;
        else if(s[i]=='G')e++;
        else f++;
    }
    int x,y;

    for(i=0;i<n;i++)
    {
        if(s[i]=='R')d--;
        else if(s[i]=='G')e--;
        else {f--;}

        if(s[i]=='R')
        {
            ans+=(b*f);
            ans+=(c*e);
        }
        else if(s[i]=='G'){
          //  cout<<a<<" "<<f<<"\n";
            ans+=(a*f);
            ans+=(c*d);
        }
        else{
            ans+=(a*e);
            ans+=(b*d);
        }
        x=i-1;
        y=i+1;

        while(x>=0&&y<n)
        {
            if(go(x,i,y))ans--;
            x--; y++;
        }

        if(s[i]=='R'){a++;}
        else if(s[i]=='G'){b++;}
        else c++;
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++)
            cin>>v[i];

    int cnt=0;
    k--;

    for(int i=0;i<n;i+=k){
         if(i!=n-1)
            cnt++;
    }

    cout<<cnt<<endl;



    return 0;
}


Measured memory_bytes: 640
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {n:String}
    let t = n.chars().last().unwrap();
    if t == '3' {
        println!("bon");
    } else if t == '0' || t == '1' || t == '6' || t == '8' {
        println!("pon");
    } else {
        println!("hon");
    }
}


Measured memory_bytes: 2152
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
    int from,to;
    int cost;

    edge(int t,int c) : to(t),cost(c) {}
    edge(int f,int t,int c) : from(f),to(t),cost(c) {}

    bool operator<(const edge &e) const {
        return cost < e.cost;
    }
};

vector<edge> G[1005];
int d[1005];

void dijkstra(int s,int n) {
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+n,INF);

    d[s] = 0;
    que.push(P(0,s));

    while(que.size()) {
        P p = que.top();
        que.pop();

        int v = p.second;
        if(d[v] < p.first) continue;

        rep(i,G[v].size()) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main() {
    int n,m;

    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;

        rep(i,n*m) {
            G[i].clear();
        }

        int type;
        rep(i,m) {
            rep(j,n-1) {
                cin >> type;
                if(type == 0) {
                    int s = n*i + j;
                    int t = n*i + j+1;
                    
                    G[s].push_back(edge(t,1));
                    G[t].push_back(edge(s,1));
                }
            }

            if(i == m-1) break;
            rep(j,n) {
                cin >> type;
                if(type == 0) {
                    int s = n*i + j;
                    int t = n*(i+1) + j;

                    G[s].push_back(edge(t,1));
                    G[t].push_back(edge(s,1));
                }
            }
        }

        
        dijkstra(0,n*m);

        if(d[n*m-1] == INF) cout << 0 << endl;
        else cout << d[n*m-1] + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 1284
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long ll;

void printV(vector<ll> v){
    cout << "[vector]" << endl;
    int n = v.size();
    for(int i=0; i<n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

void add_to_C(vector<ll>& C, ll val, int num){
    for(int i=0; i<num; i++){
        C.push_back(val);
    }
}

ll calc_sum(vector<ll> C, vector<ll> A){
    ll sum = 0;
    int n = C.size();

    for(int i=0; i<n; i++){
        sum += C[i] * A[i];
    }
    return sum;
}

void minus_descend(vector<ll>& C){
    int n = C.size();
    for(int i=0; i<n; i++){
        C[i] *= -1;
    }
    sort(C.begin(), C.end(), std::greater<ll>());
}

int main(){
    // input
    int N;
    cin >> N;

    vector<ll> A(N);
    for (int i = 0; i < N; ++i){
        cin >> A[i];
    }
    sort(A.begin(), A.end(), std::greater<ll>()); // descending

    ll sumMax = 0;
    /*
    if(N==2){
        sumMax = abs(A[0] - A[1]);
        cout << sumMax << endl;
        return 0;
    }
    */

    vector<ll> C(0); // coefficient array, always descending
    
    if(N%2 == 1){
        // from upper
        ll minus_two_num = (N - 2 + 1) / 2;
        ll plus_two_num = N - 2 - minus_two_num;
        add_to_C(C, 2, plus_two_num);
        add_to_C(C, 1, 2);
        add_to_C(C, -2, minus_two_num);
        sumMax = calc_sum(C, A);

        // from lower
        minus_descend(C);
        ll sumMax2 = calc_sum(C, A);

        sumMax = max(sumMax, sumMax2);
    }
    else{
        // from upper
        ll minus_two_num = (N - 2) / 2;
        ll plus_two_num = (N - 2) / 2;
        add_to_C(C, 2, plus_two_num);
        add_to_C(C, 1, 1);
        add_to_C(C, -1, 1);
        add_to_C(C, -2, minus_two_num);
        sumMax = calc_sum(C, A);

        // from lower
        minus_descend(C);
        ll sumMax2 = calc_sum(C, A);

        sumMax = max(sumMax, sumMax2);        
    }

    // output
    cout << sumMax << endl; 
    
    return 0;
}

Measured memory_bytes: 3444
from decimal import *

n=int(input())
l=list(map(int, input().split(' ')))
q=int(input())
freqs=[]
add=Decimal(0)
for i in l:
    if i>=len(freqs):
        freqs+=(i-len(freqs)+1)*[0]
    freqs[i]+=1
    add+=i

        
for i in range(q):
    b,c=map(int, input().split(' '))
    if b<len(freqs):
        add+=Decimal((c-b)*(freqs[b]))
        if c>=len(freqs):
            freqs+=(c-len(freqs)+1)*[0]
        freqs[c]+=freqs[b]
        freqs[b]=0
    print(add)

    


Measured memory_bytes: 204396
N, Y = list(map(int, input().split()))
list_m = [-1, -1, -1]
for a in range(N+1):
  for b in range(N-a+1):
    c = N - (a+b)
    if 10000*a + 5000*b + 1000*c == Y:
      list_m = [a, b, c]
    else:
      continue
print(list_m[0], list_m[1], list_m[2])

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

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

bool mp[222222];
int v[222222];
int n,h;

bool check(int mid){
	REP(i,n){
		if(v[i] >= mid)mp[i] = true;
		else mp[i] = false;
	}
	
	DBG(SHOW1d(mp,n);)
		
	if(mp[n/2] == mp[n/2+1] || mp[n/2] == mp[n/2-1]){
		return mp[n/2];
	}
	else {
		int ret = 0, mi;
		int L = n/2;
		int R = n/2;
		while(L > 0 && mp[L] != mp[L-1])L--;
		if(L == 0)L--;
		while(R < n && mp[R] != mp[R+1])R++;
		if(R == n)R++;
		if(R != n+1 && abs(n/2 - L) > abs(n/2 - R)){
			return mp[R];
		}
		else if(L != -1 && abs(n/2 - L) <= abs(n/2 - R)){
			return mp[L];
		}
		else{
			return (mp[n/2] + (h % 2) + 1) % 2;
		}
	}
}

int main(){
	
	cin >> h;
	n = 2 * h - 1;
	REP(i,n)cin >> v[i];
	
	int low_b = 1;
	int up_b = n;
	
	while(abs(up_b - low_b) > 1){
		int mid = (up_b + low_b) / 2;
		if(check(mid))low_b = mid;
		else up_b = mid;
	}
	
	cout << low_b << endl;
	return 0;
}

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

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

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

int main(void){
    int n,m;
    cin >> n >> m;
    int s[m],c[m];
    for(int i = 0;i < m;i++)cin >> s[i] >> c[i];
    
    bool check = true;
    for(int i = 0;i < m;i++){
        for(int j = 0;j < m;j++){
            if(s[i] == s[j] && c[i] != c[j])check = false;
            if(n > 1 && s[j] == 1 && c[j] == 0)check = false;
        }
    }
    
    if(!check)cout << -1 << endl;
    else {
        for(int i = 1;i <= n;i++){
            int b = 0;
            for(int j = 0;j < m;j++){
                if(s[j] == i)b = c[j];
            }
            if(i == 1 && b == 0){
                if(n > 1)cout << 1;
                else cout << 0;
            } else cout << b;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    double r;
    double a,b;
    cin>>r;
    a=r*r*3.141592653589;
    b=2*r*3.141592653589;
    printf("%f %f\n",a,b);
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
        using namespace std;
         
        using ll = long long;
         
        #define INF (1LL << 31 - 1)
        #define MOD int(1e9+7)
        #define repi(i,j,n) for(int i = (j); i < (n); ++i)
        #define rep(i,n) repi(i,0,n)
        #define fi first
        #define se second
         
        inline void init() {
            cin.tie(0);
            ios::sync_with_stdio(false);
        }
         
        int n, dp[301][301], a[301][301];
        bool used[301][301];
         
        int main() {
            init();
         
            cin >> n;
            rep(i,n){
                rep(j,n) {
                    cin >> a[i][j];
                    dp[i][j] = a[i][j];
                }
            }
         
         
            rep(k,n) {
                rep(i,n) {
                    rep(j,n) {
                        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                    }
                }
            }
         
            rep(i,n) {
                rep(j,n) {
                    if (a[i][j] != dp[i][j]) {
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
         
            ll sum = 0;
            bool flag;
         
            rep(i,n) {
                repi(j,i+1,n) {
                    flag = false;
         
                    rep(k,n) {
                        if (i != k and j != k and dp[i][j] == dp[i][k] + dp[k][j]) {
                            flag = true;
                        }
                    }
         
                    if (!flag) sum += dp[i][j];
                }
            }
         
            cout << sum << endl;
         
            return 0;
        }

Measured memory_bytes: 1024
# =map(int,input().split())
n,m=map(int,input().split())
a =[list(map(int,input().split())) for i in range(n)]
a.sort()
import sys
# ans=dict(a)
# print(a)
cnt=0
for i in range(n):
    z=cnt+a[i][1]
    if z>=m:
        print(a[i][0])
        sys.exit()
    else:
        cnt=z

# print(a)
# for i in range(n):
#     for k in range(a[i][1]):
#         ans.append(a[i][0])
# print(ans)
# ans=[int(i) for i in ans]
# print(ans)
# print(ans[m-1])


Measured memory_bytes: 27872
using System;
using System.Collections.Generic;
using System.Linq;
class c{
  public static void Main(){
    String[] str = Console.ReadLine().Split(' ');
    int x = int.Parse(str[0]);
    int n = int.Parse(str[1]);
    int ans = 10000;
    int dis = 10000;
    if(n == 0){
      ans = x;
    }
    else{
      int[] num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
      bool[] f = new bool[501];
      for(int i=0; i<n; i++){
        f[num[i]+250] = true;
      }
      for(int i=-250; i<=250; i++){
        if((int)Math.Abs(i-x) < dis && !f[i+250]){
          ans = i;
          dis = (int)Math.Abs(i-x);
        }
      }
    }
    Console.WriteLine(ans);
  }
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = (A + B);
  int R = (C + D);
  if(L > R){
    cout << "Left" << endl;
  }else if(L < R){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}


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

int main() {
	int a, b, c, k;
	cin >>a >> b >> c >> k;
	int d = max(max(a, b), c), e = (a + b + c) - max(max(a, b), c);
	for (int i = 0; i < k ; i++){
		d = d * 2;
	}
	cout << d + e<< endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const LL ONE=1;
const int MOD=2019;//2019=3*673
int L,R;LL Ans=MOD;
int main(){
	scanf("%d%d",&L,&R);
	int cnt0=R/3-(L-1)/3;
	int cnt1=R/673-(L-1)/673;
	if(cnt0&&cnt1)Ans=0;
	else{
		for(int i=L;i<=R;i++)
			for(int j=i+1;j<=R;j++)
				Ans=min(Ans,(ONE*i*j)%MOD);
	}
	printf("%lld\n",Ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double theta) {
    if(theta > PI / 2.0 - EPS) {
        return 0.0;
    }
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void solve() {
    input();
    long double ok = PI / 2.0;
    long double ng = 0.0;
    for(int _ = 1; _ <= 30; _++) {
        long double mid = (ok + ng) / 2.0;
        if(f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok / PI * 180 << endl;
    return;
}

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


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

using namespace std;

vector<bool> D;

bool check(int N) {
    int n=N;
    while(n) {
        if(!D[n%10]) {
            return false;
        }
        n /= 10;
    }
    return true;
}

int main() {
    int N, K;
    cin >> N >> K;
    
    D.assign(N+1, true);
    for(int k=0; k<K; k++) {
        int d;
        cin >> d;
        D[d]=false;
    }
    
    while(1) {
        if(check(N)) {
            break;
        }
        N++;
    }
    cout << N << endl;
    

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int type[100];
int cnt[100][3][3];

int main() {

  int N, K;
  cin >> N >> K;

  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    type[a-1] = b;
  }

  if (type[0] == 0 && type[1] == 0) for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cnt[1][i][j] = 1;
  if (type[0] != 0 && type[1] == 0) for (int i = 0; i < 3; i++) cnt[1][type[0]-1][i] = 1;
  if (type[0] == 0 && type[1] != 0) for (int i = 0; i < 3; i++) cnt[1][i][type[1]-1] = 1;
  if (type[0] != 0 && type[1] != 0) cnt[1][type[0]-1][type[1]-1] = 1;

  for (int index = 1; index < N; index++) {
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (type[index] > 0 &&  type[index]-1 != j) {
          cnt[index][i][j] = 0;
          continue;
        }
        if (i != j) {
          cnt[index][i][j] += cnt[index-1][0][i] + cnt[index-1][1][i] + 
            cnt[index-1][2][i];
        } else {
          cnt[index][i][j] += cnt[index-1][(i+1)%3][j] + cnt[index-1][(i+2)%3][j];
        }
        cnt[index][i][j] = cnt[index][i][j] % 10000;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      ans += cnt[N-1][i][j];
    }
  }
  cout << ans % 10000 << endl;

  return 0;

}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll a, ll b, ll x) {
  double ans;

  if (x >= 0.5 * a * a * b) {
    ans = atan(2.0 * (a * a * b - x) / (a * a * a));
  } else {
    ans = 0.5 * M_PI - atan(2.0 * x / (a * b * b));
  }
  cout << ans * 180.0 / M_PI << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll a;
  scanf("%lld", &a);
  ll b;
  scanf("%lld", &b);
  ll x;
  scanf("%lld", &x);
  solve(a, b, x);
  return 0;
}


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


int main() {
    int N,T; cin >> N >> T;
    vector<int> t(N);
    for(int i = 0; i < N; i ++) cin >> t[i];
    int s = 0;
    int ans = T;
    for(int i = 0; i < N-1; i++) {
        int now = t[i+1] - t[i];
        ans += min(now,T);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 401;

using namespace std;

int h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
bool color[N][N],vis[N][N];
ll black=0,white=0;

bool inside (pair<int,int> cor, int d)
{
    int x=cor.ff+dx[d],y=cor.ss+dy[d];
    return (x>=0 && x<h && y>=0 && y<w);
}

bool check (pair<int,int> g, int cx, int cy)
{
    return (color[g.ff][g.ss]!=color[cx][cy]);
}

void bfs (pair<int,int> s)
{
    queue<pair<int,int>> q;
    q.push(s);
    vis[s.ff][s.ss]=true;
    int i;
    while (!q.empty())
    {
        pair<int,int> v=q.front();
        q.pop();
        int x=v.ff,y=v.ss;
        if (color[x][y])
            black++;
        else
            white++;
        for (i=0;i<4;i++)
        {
            int cx=x+dx[i],cy=y+dy[i];
            if (inside(v,i) && check(v,cx,cy))
            {
                if (vis[cx][cy]==true)
                    continue;
                q.push(mp(cx,cy));
                vis[cx][cy]=true;
            }
        }
    }
}

main()
{
    fast;
    int i,j;
    cin>>h>>w;
    string s;
    for (i=0;i<h;i++)
    {
        cin>>s;
        for (j=0;j<w;j++)
            color[i][j]=(s[j]=='#');
    }
    ll ans=0;
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
        {
            if (vis[i][j])
                continue;
            black=0;
            white=0;
            bfs(mp(i,j));
            ans+=black*white;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;
int main(){
	string inputstr;
	cin >> inputstr;
	int count = 0;
	for(int i = 0; i < inputstr.length(); i++){
		if (inputstr[i] == '1') count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
S=input()
a=[0]*7
a[0]=int(S[0])
a[2]=int(S[1])
a[4]=int(S[2])
a[6]=int(S[3])
for i in range(2**3):
    j=bin(int(i))[2:]
    while len(j)<3:
        j="0"+j
    for k in range(3):
        if j[k]=="0":
            a[2*k+1]="+"
        else:
            a[2*k+1]="-"
    ans=a[0]
    if a[1]=="+":
        ans+=a[2]
    else:
        ans-=a[2]
    if a[3]=="+":
        ans+=a[4]
    else:
        ans-=a[4]
    if a[5]=="+":
        ans+=a[6]
    else:
        ans-=a[6]
    if ans==7:
        print(S[0]+a[1]+S[1]+a[3]+S[2]+a[5]+S[3]+"=7")
        break


Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  auto b = a;
  sort(ALL(b));

  map<int, int> even, odd;
  rep(i, n) {
    if (i % 2 == 0) even[b[i]]++;
    else odd[b[i]]++;
  }

  int num = 0;

  rep(i, n) {
    if (i % 2 == 0 && even[a[i]] >> 0) {
      even[a[i]]--;
    } else if (i % 2 ==1 && odd[a[i]] > 0) {
      odd[a[i]]--;
    } else {
      num++;
    }
  }

  int ans = num / 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13504
/*
神题
朴素DP-->O(n^3)
DP：f[i][j]=填完了前i-1个数，当前需要考虑的区间[i,R]中需要填入j个1，方案数
ans=f[n+1][0]
转移枚举i位置的数即可O(1)转移
O(n^2)
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 3010
#define mod 1000000007
using namespace std;
int n, m, x, y, f[N][N], s[N], sum, R[N];
char S[N];
int main(){
	scanf("%d%d%s", &n, &m, S+1);
	s[0]=0; for(int i=1; i<=n; i++)s[i]=s[i-1]+S[i]-'0'; s[n+1]=s[n];
	for(int i=1; i<=n+1; i++)R[i]=i;
	for(int i=1; i<=m; i++){scanf("%d%d", &x, &y); R[x]=max(R[x], y);}
	memset(f, 0, sizeof(f)); f[1][s[R[1]]]=1; x=R[1];
	for(int i=1; i<=n; i++){
		y=max(x, R[i+1]); sum=s[y]-s[x];
		for(int j=0; j<=x-i+1; j++){
			if(j)f[i+1][j-1+sum]=(f[i+1][j-1+sum]+f[i][j])%mod;
			if(j<=x-i)f[i+1][j+sum]=(f[i+1][j+sum]+f[i][j])%mod;
		}
		x=y;
	}
	printf("%d", f[n+1][0]);
	return 0;
}

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

// main.cpp

int main() {
  std::string abcd;
  std::cin >> abcd;
  const std::int_fast64_t a = abcd[0] - '0';
  const std::int_fast64_t b = abcd[1] - '0';
  const std::int_fast64_t c = abcd[2] - '0';
  const std::int_fast64_t d = abcd[3] - '0';

  for (std::int_fast64_t op1 = -1; op1 <= 1; op1 += 2) {
    for (std::int_fast64_t op2 = -1; op2 <= 1; op2 += 2) {
      for (std::int_fast64_t op3 = -1; op3 <= 1; op3 += 2) {
        if (a + op1 * b + op2 * c + op3 * d == 7) {
          std::cout << a << (op1 > 0 ? '+' : '-') << b << (op2 > 0 ? '+' : '-') << c << (op3 > 0 ? '+' : '-') << d << "=7" << std::endl;
          return 0;
        }
      }
    }
  }

  return EXIT_FAILURE;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;




int main() {
	ll i, j, k;
	ll N, M, K;
	cin >> N >> M;
	if (N*500 >= M)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int m[53][53],sum,ch[4];

int dfs(int i,int j){
  if(m[i][j]==2){
    ch[2]=1;
  }else if(m[i][j]==3){
    ch[3]=1;
  }else if(m[i][j]==1){    
    sum++;
    m[i][j]=0;
    if(m[i-1][j]>0)dfs(i-1,j);
    if(m[i][j-1]>0)dfs(i,j-1);
    if(m[i+1][j]>0)dfs(i+1,j);
    if(m[i][j+1]>0)dfs(i,j+1);
  }
}

int main(){
  int wh,b,w,h;
    char s;
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    for(int i=0;i<=h+1;i++){
      for(int j=0;j<=w+1;j++){
	m[i][j]=0;
      }
    }
    b=0;wh=0;

    for(int i=1;i<=h;i++){//テ・ツ?・テ・ツ環?
      for(int j=1;j<=w;j++){
	cin>>s;
	if(s=='.')m[i][j]=1;
	else if(s=='W')m[i][j]=2;
	else if(s=='B')m[i][j]=3;
      }    
    }

    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	if(m[i][j]==1){
	  sum=0;
	  ch[2]=0;
	  ch[3]=0;
	  dfs(i,j);
	  if(ch[2]==1&&ch[3]==0)wh+=sum;
	  else if(ch[3]==1&&ch[2]==0)b+=sum;
	  /*for(int i=0;i<=h+1;i++){////////////
	    for(int j=0;j<=w+1;j++){
	      cout<<m[i][j];
	    }
	    cout<<endl;
	  }
	  cout<<ch[2]<<" "<<ch[3]<<endl;//////////*/
	}
      }
    }
    cout<<b<<" "<<wh<<endl;
  }

  return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v(n-1);
    bool has1 = false;
    for (int i = 1; i < n; i++) {
        v[i-1] = abs(s[i] - s[i-1]);
        if (v[i-1] == 1) has1 = true;
    }

    if (has1) {
        for (int i = 0; i < v.size(); i++) {
            if (v[i] == 2) {
                v[i] = 0;
            }
        }
    } else {
        for (int i = 0; i < v.size(); i++) {
            if (v[i] == 2) {
                v[i] = 1;
            }
        }
    }

    while (v.size() > 1) {
        int x = v.size();
        int len = 1;
        while (x > 1) {
            x /= 2;
            len *= 2;
        }
        vector<int> nv;
        int curr = 0;
        for (int i = 0; i < len; i++) {
            curr += v[i];
            curr %= 2;
        }
        nv.push_back(curr);
        for (int i = len; i < v.size(); i++) {
            curr += v[i-len];
            curr += v[i];
            curr %= 2;
            nv.push_back(curr);
        }
        v = nv;
    }

    int ans = v[0];
    if (!has1) {
        if (ans == 1) ans = 2;
    }
    cout << ans << endl;

    return 0;
}


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

struct uf{
    vector<int> t;
    uf(int n):t(n,-1){}
    int r(int x){
        while(t[x] >= 0){
            if(t[t[x]] >= 0){
                t[x] = t[t[x]];
                x = t[x];
            }else{
                x = t[x];
            }
        }
        return x;
    }
    int f(int x,int y){return r(x)==r(y);}
    int u(int x,int y){x=r(x);y=r(y);if(t[x]>t[y])swap(x,y);t[x]+=t[y];t[y]=x;}
    template<class F,class... R>
    int u(F f,R... r){for(auto i:initializer_list<int>{r...})u(f,i);}
};

int main(){
    uf uf1(13);
    uf1.u(1,3,5,7,8,10,12);
    uf1.u(4,6,9,11);
    int a, b;
    cin >> a >> b;
    puts(uf1.f(a, b) ? "Yes" : "No");
}

Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, x = LI()
    A = LI()

    min_a, min_i = INF, -1
    res = 0
    for i, a in enumerate(A):
        if a < min_a:
            min_a = a
            min_i = i
        res += a
    A = A[min_i:] + A[:min_i]

    dp = [INF] + A
    for k in range(n - 1):
        tmp = 0
        for i in range(n)[::-1]:
            if dp[i + 1] > dp[i]:
                dp[i + 1] = dp[i]
            tmp += dp[i + 1]

        res = min(res, tmp + (k + 1) * x)

    return res


print(main())


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if ((a==b)&&(b==c)) {
    cout << "No"<< endl;
  }
  else if ((a!=b)&&(b!=c)&&(c!=a)) {
    cout << "No"<< endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;

using namespace std;

LL q,x,y,z,n,m,p[KL],mn=1e9,mx=-1e9,ans;
string t;
vector <LL> vec;
set <int> s;
map <int,int> M;


int main()
{
    cin>>t;
    if(t[2]==t[3] && t[4]==t[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main() {
    int N, L;
    cin >> N >> L;
    string str[N];
    for (int i = 0; i < N; i++) {
        cin >> str[i];
    }
    sort(str, str+N);
    
    string res = "";
    for (int i = 0; i < N; i++) {
        res += str[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256