akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
a=list(map(int,input().split()))
D=[2,5,5,4,5,6,3,7,6]
dp=[]
dp.append([0,0,0,0,0,0,0,0,0,0])
for i in range(n):
  dp.append([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])
allowed=[]
for i in a:
  allowed.append([i,D[i-1]])
for i in range(n):
  for j in allowed:
    temp=i+j[1]
    if temp<n+1 and dp[i][0]!=-1:
      if dp[temp][9]<dp[i][9]+1:
        for k in range(10):
          dp[temp][k]=dp[i][k]
        dp[temp][9]+=1
        dp[temp][j[0]-1]+=1
      elif dp[temp][9]==dp[i][9]+1:
        change=0
        for k in range(8,-1,-1):
          if k!=j[0]-1:
            breakflag=0
            if dp[temp][k]>dp[i][k]:
              change=-1
              breakflag=1
            if dp[temp][k]<dp[i][k]:
              change=1
              breakflag=1
          else:
            breakflag=0
            if dp[temp][k]>dp[i][k]+1:
              change=-1
              breakflag=1
            if dp[temp][k]<dp[i][k]+1:
              change=1
              breakflag=1
          if breakflag==1:
            break
        if change==1:
          for k in range(10):
            dp[temp][k]=dp[i][k]
          dp[temp][9]+=1
          dp[temp][j[0]-1]+=1
ans=[]
for i in range(8,-1,-1):
  for j in range(dp[n][i]):
    ans.append(str(i+1))
print(''.join(ans))

Measured memory_bytes: 75892
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int K = in.nextInt();
            int X = in.nextInt();
            out.println(K * 500 >= X ? "Yes" : "No");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
    std::string str;
    int sum;
    while(std::cin >> str && str != "0"){
        sum = 0;
        for (int i = 0, l = str.size(); i < l;i++)
            sum += str[i] - '0';
        std::cout << sum << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

static size_t A[100000];

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

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

	return result;
}

int main(void) {
	size_t N;
	size_t prevT = 0;
	size_t prevX = 0;
	size_t prevY = 0;
	bool executable = true;

	scanf("%zu\n", &N);
	for (size_t idx = 0; idx < N; idx++) {
		size_t t, x, y;
		scanf("%zu %zu %zu", &t, &x, &y);
		if (idx < N - 1) {
			scanf("\n");
		}

		const size_t duration = t - prevT;
		const size_t distance = ABSS(prevX, x) + ABSS(prevY, y);
		if (duration < distance || (duration - distance)%2 != 0) {
			executable = false;
			break;
		}
	}

	puts((executable ? "Yes" : "No"));

	return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] w=new int[n];
		for(int i=0;i<n;i++){
			w[i]=sc.nextInt();
		}
		int[] z=new int[n];
		for(int t=0;t<n-1;t++){
			int s1=0;
			int s2=0;
			for(int i=0;i<=t;i++){
				s1+=w[i];
			}
			for(int j=t+1;j<n;j++){
				s2+=w[j];
			}
			z[t]=s1-s2;
			if(z[t]<0)
			z[t]=-z[t];
		}
		int min=z[0];
		for(int i=0;i<n-1;i++){
			if(min>z[i])
				min=z[i];
		}
		System.out.println(min);
	}
		
}

Measured memory_bytes: 23252
n, k, q = gets.chomp.split.map(&:to_i)
point = Array.new(n, k-q)
q.times do
  a = gets.chomp.to_i - 1
  point[a] += 1
end

n.times do |i|
  if point[i] > 0
    puts('Yes')
  else
    puts('No')
  end
end

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

int main() {
  int n;
  cin >> n;
  int one = n%10;
  if(one==3)
    cout << "bon" << endl;
  else if(one==0 || one==1 || one==6 || one==8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 20; int n, m;
bool visited[maxN][maxN];
char maze[maxN][maxN + 1];

int di[4] = {0, 0, 1, -1}, dj[4] = {1, -1, 0, 0};
struct Node
{
  int i, j, d;
};
int mostDistant(int si, int sj)
{
  memset(visited, false, sizeof(visited));
  queue<Node> q; q.push({si, sj, 0});
  int md = 0;
  while (!q.empty())
  {
    Node u = q.front(); q.pop();
    if (u.i < 0 || u.j < 0 || u.i >= n || u.j >= m || visited[u.i][u.j] || maze[u.i][u.j] == '#') continue;
    visited[u.i][u.j] = true, md = max(md, u.d);
    for (int k = 0; k < 4; k ++)
      q.push({u.i + di[k], u.j + dj[k], u.d + 1});
  }
  return md;
}

int main()
{
  while (scanf("%d %d", &n, &m) != EOF)
  {
    for (int i = 0; i < n; i ++)
      scanf(" %s", maze[i]);

    int ans = 0;
    for (int i = 0; i < n; i ++)
      for (int j = 0; j < m; j ++)
        ans = max(ans, mostDistant(i, j));
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    deque<char> que1, que2;
    bool turn = false;
    int Q; cin >> Q;
    while(Q--) {
        int q; cin >> q;
        if(q == 1) {
            turn = !turn;
        } else {
            int f; char c; cin >> f >> c;
            if(f == 1 && !turn) que1.push_front(c);
            else if(f == 2 && !turn) que2.push_back(c);
            else if(f == 1 && turn) que2.push_back(c);
            else que1.push_front(c);
        }
        // for(auto& e: que1) cout << e;
        // cout << "*" << S << "*";
        // for(auto& e: que2) cout << e;
        // cout << endl;
    }
    if(turn) {
        reverse(S.begin(), S.end());
        reverse(que1.begin(), que1.end());
        reverse(que2.begin(), que2.end());
        swap(que1, que2);
    }
    for(auto& e: que1) cout << e;
    cout << S;
    for(auto& e: que2) cout << e;
    cout << endl;

    return 0;
}
// S1 T S2
// 2 a
// S1 = a
// 2 b
// S1 = ba

Measured memory_bytes: 848
#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);

  int turn = 1;
  int ans[400010] = {0}, start = 200005, end = 200005;

  for(int i=1; i<=n; i++){
    int a; scanf("%d", &a);
    if(turn == 1)
      ans[end++] = a;
    else
      ans[--start] = a;
    turn *= (-1);
  }
  
  if(turn < 0)
    for(int i=end-1; i>=start; i--)
      printf("%d ", ans[i]);
  else
    for(int i=start; i<end; i++)
      printf("%d ", ans[i]);
  puts("");

  return 0;
}


Measured memory_bytes: 3712
m, k = map(int, input().split())
if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
else:
    if k < 2 ** m:
        for i in range(2 ** m):
            if i != k:
                print(i, end = ' ')
        print(k, end = ' ')
        for i in reversed(range(2 ** m)):
            if i != k:
                print(i, end = ' ')
        print(k)
    else:
        print(-1)

Measured memory_bytes: 54104
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define mod 1000000007
#define ll long long
int a[nn];int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	for(int i=0;i<=n;i++)
	{
		if(a[i+1]<i+1)
		{
			int cnt=0;
			for(int j=i+1;j<=n;j++) if(a[j]>=i) cnt++;
			if(cnt%2 or (a[i]-i)%2) puts("First");
			else puts("Second");
			return 0;
		}
	}
	return 0;
} 


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        Array.Sort(seqA);
        Array.Reverse(seqA);

        var total = seqA.Sum();

        var p = seqA.TakeWhile(x => x * 4 * m >= total).Count() >= m;
        
        Console.WriteLine(p ? "Yes" : "No");
    }
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename P, typename Q>
istream& operator >> (istream& is, pair<P, Q>& p)
{
  is >> p.first >> p.second;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v)
{
  each (i, v) is >> i;
  return is;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int d, n;
  while (cin >> d >> n) {
    cout << n + (n == 100) << string(d * 2, '0') << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
using System;
 
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    if(a > c) Swap(ref a, ref c);
    if(a > b) Swap(ref a, ref b);
    if(b > c) Swap(ref b, ref c);
    
    Console.WriteLine(c - a);
  }
  
  static void Swap(ref int x, ref int y)
  {
    int tmp;
    tmp = x;
    x = y;
    y = tmp;
  }
  
}

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

std::vector<int> nodes[200001];
int N, a, b, gmax;

int find_max(int nd, int from) {
    int m1 = 0, m2 = 0;
    for (int i = 0; i < nodes[nd].size(); i++) {
        if (nodes[nd][i] == from)
            continue;
        int tmp = 1+find_max(nodes[nd][i], nd);
        if (tmp >= m1) {
            m2 = m1;
            m1 = tmp;
        } else if (tmp > m2) {
            m2 = tmp;
        }
    }
    if (m1 + m2 > gmax)
        gmax = m1 + m2;
    return m1;
}

bool win[200002];

int main() {
    std::cin >> N;
    win[0] = true;
    win[1] = false;
    win[2] = true;
    for (int i = 1; i < N; i++) {
        std::cin >> a >> b;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    find_max(1, 0);
    for (int i = 3; i <= gmax; i++)
        win[i] = !win[i-1] || !win[i-2];
    if (win[gmax])
        std::cout << "First\n";
    else
        std::cout << "Second\n";
    return 0;
}


Measured memory_bytes: 26368
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        string A = cin.next();
        string B = cin.next();
        if (A == B) Console.WriteLine("H");
        else Console.WriteLine("D");
    }




}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(){
  int n,m,i,d[200010];
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=m;i<n;i++)printf("%s\n",d[i-m]<d[i]?"Yes":"No");
  return 0;
}


Measured memory_bytes: 2444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;

#define mod             1e9+7
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";
#define read(x)         freopen("in.txt","r",stdin);
#define write(x)        freopen("out.txt","w",stdout);
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define sz              3000005

int main(){
    Fast;///using Fast I/O
    int a,b,c, i,j,k, t,n,m;

    cin>>k;
    while(k--){
        cout<<"ACL";
    }
    cout<<endl;





    return 0;
}



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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

bool isPrime(int x) {
	for (int d = 2; d * d <= x; d++) {
		if (x % d == 0) return false;
	}
	return true;
}

void solve() {
	int x;
	cin >> x;
	while (!isPrime(x)) {
		x++;
	}
	cout << x;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

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

int H, W;
ll dp[1009][1009];
char c[1009][1009];
const ll MOD = 1e9 + 7;

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

    cin >> H >> W;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            cin >> c[i][j];
        }
    }

    dp[0][1] = 1;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (c[i][j] == '.')
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= MOD;
                dp[i][j] += MOD;
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[H][W];
}

Measured memory_bytes: 12488
#include <stdio.h> 
int main(void) 
{ 
  int a, b, r, tmp; 

   scanf("%d %d", &a,&b); 


  if(a<b){ 

    tmp = a; 
    a = b; 
    b = tmp; 


  } 
  r = a % b; 


  while(r!=0){ 

    a = b; 
    b = r; 
    r = a % b; 


  } 

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

  return 0; 
} 

Measured memory_bytes: 1844
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection.Metadata.Ecma335;
using System.Numerics;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;
        public static void Main()
        {

            var num = long.Parse(Console.ReadLine());

            if (num == 1)
            {

                Console.WriteLine(0);
                return;

            }

            Dictionary<long, int> result = new Dictionary<long, int>();

            Solve(num);
            int ans = 0;

            foreach (var data in result)
            {

                ans += (int)((-1 + Math.Sqrt(1 + 8 * data.Value)) / 2.000);

            }
            Console.WriteLine(ans);

            void Solve(long num)
            {

                long res = num;
                for (long k = 2; k * k <= num; k++)
                    if (num % k == 0)
                    {

                        if (result.ContainsKey(k)) result[k]++;
                        else result.Add(k, 1);
                        res = num / k;
                        break;

                    }

                if (num == res)
                    if (result.ContainsKey(res))
                        if (result[res] == 1)
                            return;

                        else result[res]++;
                    else result.Add(res, 1);

                else Solve(res);

            }
        }

    }

}


Measured memory_bytes: 27844
from fractions import gcd

# gcd(A,B)の素因数分解したときの素数の数+1が最大
# なぜならば任意の公約数C|A,C|BはC|gcd(A,B)
# Cとして素因数+1より大きいの数を選ぶと、Cはどこかの素数で重複して互いに素にならない

A,B = map(int, input().split())
D = gcd(A,B)

ret = 1
prime_len = 10**6+1
prime_factor = [False]*prime_len
for p in range(2, prime_len):
    while D%p == 0:
        if prime_factor[p] == False:
            ret += 1
            prime_factor[p] = True
            
        D = D//p
        
    if D == 1: break

# 10^6以下の素因数を探索して、1でなければ10^12以下の数は素数である。（10^6<p,p^\primeならば10^12 < p \cdot p^\prime）
if D != 1: ret += 1
    
print(ret)

Measured memory_bytes: 13112
#include <stdio.h>
#include <stdlib.h>

#define Limit 1000000000

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    for (int i = 0; i < Limit; i++)
    {
        if(abs(a - i) == abs(b - i))
        {
            printf("%d\n", i);
            return 0;
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

struct edge {
    int to, cost;
};

vector<edge> G[1000000];
ll d[1000000];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edge e;
        e.to = b;
        e.cost = c;
        G[a].push_back(e);
    }
    fill(d, d + N + 10, llmin);
    d[1] = 0;
    ll max = 0;
    bool inflag = false;
    for (int i = 0; i < 2 * N; i++) {
        for (int j = 1; j <= N; j++) {
            if (d[j] != llmin) {
                for (int k = 0; k < G[j].size(); k++) {
                    int t = G[j][k].to;
                    int co = G[j][k].cost;
                    if (d[t] < d[j] + co) {
                        d[t] = d[j] + co;
                    }
                }
            }
        }
        if (i == N - 1) {
            max = d[N];
        } else if (i > N - 1 && max < d[N]) {
            inflag = true;
        }
    }
    if (inflag) {
        cout << "inf" << endl;
    } else {   
        cout << max << endl;
    }
}


Measured memory_bytes: 25344
import sys
input = sys.stdin.readline

from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_c = Counter(a)
    a_c_sum = 0
    for c in a_c:
        if a_c[c] >= 2:
            a_c_sum += cmb(a_c[c], 2)

    for ea in a:
        if a_c[ea] <= 1:
            sa = 0
        elif a_c[ea] == 2:
            sa = 1
        else:
            sa = cmb(a_c[ea], 2) - cmb(a_c[ea] - 1, 2)
        print(a_c_sum - sa)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25592
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)
for i in range(m):
    x,y,z = map(int, input().split())
    x -= 1
    y -= 1
    ns[x].add(y)
    ns[y].add(x)
    
seen = [False]*n
ans = 0
for start in range(n):
    if seen[start]:
        continue
    q = [(start, -1)]
    seen[start] = True
    val = None
    while q:
        u, prev = q.pop()
        for v in ns[u]:
            if v==prev:
                continue
            if seen[v]:
                val = 1
            else:
                seen[v] = True
                q.append((v, u))
    if val is None:
        val = 1
    ans += val
print(ans)

Measured memory_bytes: 89432
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, i;
    cin >> n;
    vi h(n);
    for (i=0;i<n;i++) cin >> h[i];
    
    int cnt = 0;
    for (i=1;i<n;i++){
        int dif = h[i-1] - h[i];
        if (dif > 1){
            cout << "No" << endl;
            return 0;
        }else if (dif == 1){
            if(cnt == 1){
                cout << "No" << endl;
                return 0;
            }
            cnt++;
        }else if (dif < 0){
            cnt = 0;
        }
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, Q;
string S;
char T[MAX_N];
int A[MAX_N];

int pre(bool flipped) {
	int lv = -1, rv = N;
	while(rv - lv > 1) {
		int m = (lv + rv) / 2;
		int at = m;
		rep(i, 0, Q) {
			if(S[at] == T[i]) {
				at += (!flipped ? A[i] : -A[i]);
			}
			if(at < 0 || N <= at) break;
		}
		if(at >= 0) rv = m; //if it don't go to left
		else lv = m;
	}
	return rv;
}

void solve() {
	cin >> N >> Q;
	cin >> S;
	rep(i, 0, Q) {
		char a, b; cin >> a >> b;
		T[i] = a;
		A[i] = (b == 'L' ? -1 : 1);
	}
	int lv = pre(false);
	reverse(all(S));
	int rv = N - 1 - pre(true);
	cout << rv - lv + 1 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

typedef long int32;
typedef unsigned long uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> pii;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> graph;

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rFOR(i,a,b) for(int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x,n) FOR(i,0,n) cout << x[i] << " "; cout << endl

#define PI 3.14159265359

// Custom global variable



// ----------------------

auto main() -> int
{
  #ifdef DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  #endif
  // Fast I/O
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // Code starts here ----

  int k,n;
  cin >> k >> n;

  rFOR(i,k-1,1) {
    cout << n - i << " ";
  }
  cout << n << " ";
  FOR(i,1,k) {
    cout << n+i << " ";
  }


  // ---------------------
  #ifdef DEBUG
    cerr << endl << "Time:" << double(clock())/CLOCKS_PER_SEC << " secs" << endl;
  #endif
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/05/19
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef unsigned long long int uint64_t;
typedef long long int myint64_t;

int main()
{
	int N = 0, K = 0;
	char S[51] = {0};
	scanf("%d %d", &N, &K);
	scanf("%s", S);
	S[K-1] += 0x20;
	printf("%s\n", S);
    return 0;
}


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

int main () {
  string s, ans = "Good";
  cin >> s;
  rep(i,3) {
    if(s.at(i) == s.at(i+1)) {
      ans = "Bad";
      break;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int l,r,d;cin>>l>>r>>d;
  if(d>r)
    cout<<0<<endl;
  else
  {
  for(int i=l;i<=r;i++)
    if(i%d==0)
    {l=i;break;}
   for(int i=r;i>=0;i--)
     if(i%d==0)
     {r=i;break;}
      cout<<((r-l)/d)+1<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MM 1000000007
using namespace std;

int main()
{

    string a,b;
    cin>>a>>b;

    int ans=0;
    for (int i=0;i<3;i++)
        if (a[i]==b[i])ans++;

    cout<<ans;

}


Measured memory_bytes: 256
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		
		char a = sc.next().charAt(0), b = sc.next().charAt(0);
		if(a > b) System.out.println(">");
		if(a < b) System.out.println("<");
		if(a == b) System.out.println("=");
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll n, a[100000], b[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll husoku = 0, ans = 0;
	vector<ll> kajou;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		if(a[i] < b[i]) {
			husoku += b[i]-a[i];
			ans++;
		}
		if(a[i] > b[i]) kajou.pb(a[i]-b[i]);
	}
	sort(ALL(kajou), greater<int>());
	if(husoku == 0){
		cout << 0 << endl;
		return 0;
	}
	if(husoku > 0 and kajou.empty()){
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < kajou.size(); i++) {
		ans++;
		husoku -= kajou[i];
		if(husoku <= 0) break;
	}
	if(husoku > 0) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2424
N, K =list(map(int, input().split()))
okashi_list =[]
child_list = []
for i in range(K):
    okashi = input()
    okashi_list.append(okashi)
    child = list(map(int, input().split()))
    child_list.extend(child)
child_list = set(child_list)
D = list(range(1,N+1))
count = 0
for i in D:
    if i not in child_list:
        count = count + 1
print(count)

Measured memory_bytes: 9196
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
int INF=1000000007;
using ll=long long;

int main(){
	int n,a[30]={},b[30];
	string s[50];
	cin>>n;
	rep(i,0,30)b[i]=INF;
	rep(i,0,n){
		cin>>s[i];
		rep(j,0,30)a[j]=0;
		rep(j,0,s[i].size()){
			a[s[i][j]-'a']++;
		}
		rep(i,0,30)b[i]=min(a[i],b[i]);
	}
	string t="";
	rep(i,0,30){
		rep(j,0,b[i]){
			t+=i+'a';
		}
	}
	sort(ALL(t));
	cout<<t<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint H, W, A, B;
	cin >> H >> W >> A >> B;
	cout << H*W-(H / A) * (W / B)*A*B << endl;
}



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

int main(){
  string str,wa,tmp;
  int n,ans=0;
  cin >> wa;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> str;
    tmp = str;
    str += tmp;
    int loc = str.find(wa);
    if(loc != string::npos){
      ans++;
    }
  }
  cout << ans << endl;
}
  

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  string s;
  int K;
  cin >> s >> K;
  int cnt = 0;
  int N = s.size();
  REP(i, N){
    if(i == N-1){
      // cout << "last:" << s << " " << cnt << endl;
      s[i] = (s[i] - 'a' + K- cnt) % ('z' - 'a' + 1) + 'a';
    }
    else if(s[i] == 'a') continue;
    else if('z'+1 - s[i] + cnt <= K){
      cnt += 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }

  cout << s << endl;
  return 0;
}


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

int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ans=0;
	if(k<=a){
		ans=k;
		cout << ans << endl;
		return 0;
	}else{
		ans=a;
		k-=a;
	}
	if(k<=b){
		cout << ans << endl;
		return 0;
	}else{
		k-=b;
	}
	ans-=k;
	cout << ans << endl;
	return 0;


}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,c;
vvp a;

int main(){
	cin>>n>>c;
	a=vvp(c);
	for(int i=0;i<n;i++){
		int s,t,co;
		cin>>s>>t>>co;
		a[co-1].push_back({s,t});
	}
	vp b;
	for(int i=0;i<c;i++) if(a[i].size()){
		sort(a[i].begin(),a[i].end());
		int s=a[i][0].first,t=a[i][0].second;
		a[i].push_back({inf,inf});
		for(int j=1;j<a[i].size();j++){
			int p=a[i][j].first,q=a[i][j].second;
			if(t==p) t=q;
			else{
				b.push_back({t,s});
				s=p;t=q;
			}
		}
	}
	sort(b.begin(),b.end());
	vi d(c+1);
	for(int i=0;i<b.size();i++){
		sort(d.rbegin(),d.rend());
		int s=b[i].second,t=b[i].first;
		for(int j=0;j<c;j++) if(d[j]<s){
			d[j]=t;
			break;
		}
	}
	for(int i=0;i<=c;i++) if(!d[i]){
		cout<<i<<endl;
		break;
	}
}

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

int main(){
  int i,slen,j,sum;
  char str[81];
  sum=0;
  while(scanf("%s",str)!=EOF){
    slen=strlen(str);
    for(i=0;i<slen;i++){
      if(isdigit(str[i])){
	for(j=i+1;isdigit(str[j]);j++)
	  ;
	str[j]='\0';
	sum+=atoi(str+i);
	i=j;
      }
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl x(N);
  rep(i, N) cin >> x[i];

  ll ans = (ll)pow(10, 18);
  ll dist;

  rep(i, N - K + 1){
    if(x[i + K - 1] * x[i] < 0)
      dist = x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i]));
    else
      dist = max(abs(x[i + K - 1]), abs(x[i]));

    ans = min(ans, dist);
  }

  cout << ans << "\n";
  
  return 0;
}


Measured memory_bytes: 4008
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	char a[1005];
	int ok=0;
	scanf("%s",a);
	int len1=strlen(a);
	for(int i=0;i<len1;i++)
	{
		if(a[i]==a[len1-i-1])
			ok=1;
		else
			ok=0;
	}
	if(ok==1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	ll n;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>a[i];

	}
	int flag = 0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if(a[i]%2==0){
			if(a[i]%3==0 ||a[i]%5==0)
				continue;
			else
				flag=1;
		}

	}

	if(flag)
		cout<<"DENIED";
	else
		cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(i, c) ((c).find(i) != (c).end())
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define foreach(i, c) for(auto i : c)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watchc(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)

//=========================

int pre[100001];
vector<vi> adj;

void run_test() {
	int N, M;
    cin >> N >> M;
    adj.clear(); adj.reserve(N);
    rep(i, M) {
        int a1, a2;
        cin >> a1 >> a2;
        adj[a1-1].pb(a2-1);
        adj[a2-1].pb(a1-1);
    }
    memset(pre, -1, sizeof pre);
    queue<int> q;
    q.push(0);
    pre[0] = 0;
    while(!q.empty()) {
        int c = q.front(); q.pop();
        rep(i, sz(adj[c])) if(pre[adj[c][i]] == -1) {
            pre[adj[c][i]] = c;
            q.push(adj[c][i]);
        }
    }
    bool ok = true;
    rep(i, N) if(pre[i] == -1) ok = false;
    if(!ok) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for(int i = 1; i < N; i++)
            cout << pre[i]+1 << endl;
    }
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t;
	//while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	infile = ifstream("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl;
	cerr << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	if(infile.good()) infile.close();
}


Measured memory_bytes: 10344
#include<iostream>
using namespace std;
int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>c){
		cout<<b+c<<endl;
	}
	else if(a+b==c){
		cout<<b+c<<endl;
	}
	else{
		cout<<a+b+1+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

x = len(s)
y = len(t)

ans = []
while(x>0 and y>0):
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        x -= 1
        y -= 1
        ans.append(s[x])

print(''.join(ans[::-1]))

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  string s;
  cin >> s;
  char ch[2] = {'+','-'};
  int a = s[0]-'0',b = s[1]-'0',c = s[2]-'0',d = s[3]-'0';
  for(int bit = 0;bit < (1 << 3);bit++){
    int seven = a;
    vector<int> v(3,0);
    if(bit >> 0 & 1)v[0]++;
    if(bit >> 1 & 1)v[1]++;
    if(bit >> 2 & 1)v[2]++;
    auto add = [&](int k,int l){
      if(l == 0){
        seven += k;
      }else{
        seven -= k;
      }
    };
    add(b,v[0]);
    add(c,v[1]);
    add(d,v[2]);
    if(seven == 7){
      cout << s[0] << ch[v[0]] << s[1] << ch[v[1]] << s[2] << ch[v[2]] << s[3] << "=7";
      break;
    }
  }



  
  


  return 0;
}


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

int main(){
string S;
string T;

cin >> S;
cin >> T;
int ans;

for(int i=0; i<3; i++){
    if(S[i] == T[i]){
        ans ++;
    }
}

cout << ans << endl;

}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
*/
const int md = 998244353;


signed main()
{
    showoff;
    int n;
    cin >> n;
    int mi[n+5],h[n+5];
    FOR(i,1,n+1)
    cin >> h[i];
    mi[1] = 0;
    FOR(i,2,n+1){
    if(i-1 >= 1)mi[i] = mi[i-1]+abs(h[i]-h[i-1]);
    if(i-2 >= 1)mi[i] = min(mi[i],mi[i-2]+abs(h[i]-h[i-2]));
    }
    cout << mi[n] << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;
int Partition(int a[], int low, int high)
{
    int x = a[high];//将输入数组的最后一个数作为主元，用它来对数组进行划分
    int i = low - 1;//i是最后一个小于主元的数的下标
    for (int j = low; j < high; j++)//遍历下标由low到high-1的数
    {
        if (a[j] < x)//如果数小于主元的话就将i向前挪动一个位置，并且交换j和i所分别指向的数
        {
            int temp;
            i++;
            temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    }
    //经历上面的循环之后下标为从low到i（包括i）的数就均为小于x的数了，现在将主元和i+1位置上面的数进行交换
    a[high] = a[i + 1];
    a[i + 1] = x;
    return i + 1;
}
void QuickSort(int a[], int low, int high)
{
    if (low < high)
    {
        int q = Partition(a, low, high);
        QuickSort(a, low, q - 1);
        QuickSort(a, q + 1, high);
    }
}

int main() {
	int n,k,i,a[100000];
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int min,num;
	min=a[k-1]-a[0];
	for(i=0;i<=n-k;i++)
	{
		num=a[i+k-1]-a[i];
		if(num<min)
			min=num;
		if(min==0) break;
	}
	printf("%d\n",min);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],l,m;
bool f;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),l=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<n;++i){
		if(a[i]+a[i+1]>=l){
			f=1;
			puts("Possible");
			for(int j=1;j<i;++j) printf("%d\n",j);
			for(int j=n-1;j>=i;--j) printf("%d\n",j);
			return 0;
		}
	}
	puts("Impossible");
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
    std::vector<int> h, w;
    int tmph, tmpw;
    while(1)
    {
        cin >> tmph >> tmpw;
        if(tmph==tmpw && tmph==0) break;
        h.push_back(tmph);
        w.push_back(tmpw);
    }

    for (int t = 0; t < h.size(); t++)
    {
        for (int i = 0; i < h[t]; i++)
        {
            for (int j = 0; j < w[t]; j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}



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

using namespace std;

int digits_sum(int n) {
    int res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

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

    if (n % digits_sum(n) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  ll n, k; cin >> n >> k;
  vector<ll> grid(n);
  for (ll i = 0; i < n; i++) cin >> grid[i];
  map<ll, ll> mapp;
  ll pos = 0, cs, dist = 0, inn;
  while (true) {
    if (mapp.find(pos) != mapp.end()) {
      cs = dist-mapp[pos];
      inn = mapp[pos];
      break;
    }
    if (dist == k) {
      cout << pos + 1 << endl;
      return 0;
    }
    mapp[pos] = dist++;
    pos = grid[pos]-1;
  }
  vector<ll> path;
  for (ll i = 0; i < cs; i++) {
    path.push_back(pos);
    pos = grid[pos]-1;
  }
  cout << path[((k-inn)%cs + cs)%cs] + 1 << endl;
  return 0;
}

Measured memory_bytes: 16712