akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int X, N;
	cin >> X >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());

	int diff = 0;
	while (true) {
		if (binary_search(p.begin(), p.end(), X - diff) == false) {
			cout << X - diff << endl;
			return 0;
		}
		else if (binary_search(p.begin(), p.end(), X + diff) == false) {
			cout << X + diff << endl;
			return 0;
		}
		diff++;
		if (diff > 200) break;
	}

	return 0;

}


Measured memory_bytes: 3616
/* ex6_2
   urah  */

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

#define MAX 101  // 入力される最大の文字数 + 1(null文字)


int main(void){
    int length;
    char string[MAX];

    // 入力受け取り
    scanf("%s", string);
    // 文字列の長さの取得
    length = strlen(string);

    // 答えの出力
    printf("%c%d%c\n", string[0], length-2, string[length-1]);

    return 0;
}

Measured memory_bytes: 128
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=200005;
int a[N];
int main(){
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n,m;
    scanf("%d",&n);m=(n+1)/2;
    for (i=0;i<n;i++){
        int x,id;
        scanf("%d",&x);
        if (!i) id=m;
         else if ((i%2)^(n%2)) id=m+(i+1)/2;
          else id=m-(i+1)/2;
        a[id]=x;
    }
    for (i=1;i<=n/2;i++) swap(a[i],a[n-i+1]);
    printf("%d",a[1]);
    for (i=2;i<=n;i++) printf(" %d",a[i]);
    puts("");
  //  system("pause");
    return 0;
}


Measured memory_bytes: 2944
public class Main {
  private static void solve() {
    int n = ni();
    int k = ni();
    char[] s = ns();
    
    int[] a = new int[n + 1];
    int[] b = new int[n + 1];
    int ptr = -1;
    for (int i = 0; i < n; i ++) {
      if (i == 0 || s[i] - '0' != b[ptr]) {
        ptr ++;
        b[ptr] = s[i] == '1' ? 1 : 0;
      }
      a[ptr] ++;
    }
    ptr ++;
    int[] sum = new int[ptr + 1];
    for (int i = 0; i < ptr; i ++) {
      sum[i + 1] = sum[i] + a[i];
    }
    
    int ret = 0;
    for (int i = 0; i <= ptr; i ++) {
      int to = i + k * 2 + (b[i] == 0 ? 0 : 1);
      ret = Math.max(ret, sum[Math.min(ptr, to)] - sum[i]);
    }

    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

const int N = 52;
const int MX = 1e6 + 1e5;

struct Edge {
    int to;
    int id;
};

int a[N], n, m;
vector<Edge> G[N];
int dep[N], father[N], fat_edge[N];
int edge[N];
int dp[N][MX];

void dfs(int u, int f, int depth, int idx) {
    dep[u] = depth;
    father[u] = f;
    fat_edge[u] = idx;
    for (Edge x : G[u]) {
        if (x.to == f) continue;
        dfs(x.to, u, depth + 1, x.id);
    }
}

void paint_path(int u, int v, int bit) {
    if (dep[u] > dep[v]) swap(u, v);
    while (dep[u] < dep[v]) {
        int tmp = fat_edge[v];
        edge[tmp] |= 1ll << bit;
        v = father[v];
    }
    while (u != v) {
        int tmp = fat_edge[v];
        edge[tmp] |= 1ll << bit;
        v = father[v];
        tmp = fat_edge[u];
        edge[tmp] |= 1ll << bit;
        u = father[u];
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back({v, i});
        G[v].push_back({u, i});
    }
    dfs(1, -1, 0, 0);
    cin >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        paint_path(u, v, i);
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 0; j < MX; j++) {
            if (dp[i - 1][j] == 0) continue;
            dp[i][j | edge[i]] += dp[i - 1][j];
            dp[i][j] += dp[i - 1][j];
        }
    }
    cout << dp[n - 1][(1ll << m) - 1] << endl;
    return 0;
}


Measured memory_bytes: 377088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i <= n; i++)
        nums[i] = i+1;

    vector<int> p(n);
    vector<int> q(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    int i = 1;
    int pp = -1, qq = -1;
    do {
        if (p == nums)
            pp = i;
        if (q == nums)
            qq = i;
        i++;
    } while (next_permutation(nums.begin(), nums.end()));
    cout << abs(pp-qq) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define all(x) (x).begin(),(x).end()
#define rep(x,b,c) for(int x=b;x<c;x++)
#define  pb(x) push_back(x)
int main(){
    int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&a!=c||a==c&&a!=b||c==b&&a!=c) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[101][101];

void AdjacencyMatrices(int n){

  int i,j;
  int m,l;
  int point;

  for(i = 0;i < n;i++){
    scanf("%d%d",&m,&l);

    for(j = 0;j < l;j++){
      scanf("%d",&point);
      //printf("ok\n");
      A[m-1][point-1] = 1;
    }
  }
}

int main(){

  int n;
  int i,j;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      A[i][j] = 0;
    }
  }

  AdjacencyMatrices(n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      printf("%d",A[i][j]);
      if(j != n-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

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

int H,W;
char S[410][410];
bool Sc[410][410];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
long int b=0,w=0;

void func(int i,int j,bool isBlack){
    char ch;
    if(isBlack){
            b++; ch='.';
    }else{
            w++; ch='#';
    }
    Sc[i][j] = true;

    for (int dir = 0; dir<4; dir++){
        int nx = i + dx[dir];
        int ny = j + dy[dir];
        if (nx < 0 || ny < 0 || nx >= H || ny >= W ) continue;
        if(S[nx][ny]==ch && !Sc[nx][ny]){
               func(nx,ny,!isBlack); 
        }
    }
}

int main(){
     long int fans=0;
     cin >> H >> W;
     for (int i=0; i<H; i++){
        cin >> S[i];
     }
     for (int i=0; i<H; i++){
             for (int j=0; j<W; j++){
                     if(!Sc[i][j]){
                             func(i,j,(S[i][j]=='#'));
                             fans += w*b;
                             w = 0; b = 0;
                     }
             }
     }
     cout << fans << endl;
     return 0;
}



Measured memory_bytes: 8064
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main() {
    char o[55] = {}, e[55] = {};

    scanf("%s%s", o, e);

    for (unsigned int i = 0; i < strlen(o); ++i) {
        if (isalpha(e[i])) {
            printf("%c%c", o[i], e[i]);
        } else {
            printf("%c", o[i]);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<cstring>
#define  For(a,b)    for(int a=0;a<b;a++)
#define  si(a)       scanf("%d",&a);
#define  sl(a)       scanf("%lld",&a);
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b);
#define  queues      priority_queue
#define mod 9983
#define mem(a)  memset(a,-1,sizeof(a))
typedef long long ll;
const int INF=0x3f3f3f3f;
//queues<int,vector<int >,greater<int > >q;
// nth_element()
using namespace std;
int s[300003];
int main()
{ int a;
  string s,s1,s2;
  cin>>a>>s>>s1>>s2;
  int sum=0;
  for(int i=0;i<a;i++)
    if(s[i]!=s1[i]&&(s[i]==s2[i]||s1[i]==s2[i]))sum++;
    else if(s[i]!=s2[i]&&(s[i]==s1[i]||s2[i]==s1[i]))sum++;
   else  if(s2[i]!=s1[i]&&(s[i]==s2[i]||s1[i]==s[i]))sum++;
   else if(s[i]!=s1[i]&&s[i]!=s2[i]&&s1[i]!=s2[i])sum+=2;
  cout<<sum;
}

/******************************************
**        **             ********       **
**       ** **           **             **
**      **   **          **             **
**     **     **         **             **
**    ***********        **             **
**   **         **       ********       **
******************************************/


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

#define rep(i,n) for(ll i=0;i<n;i++)
using ll=long long;
using vl=vector<ll>;

int main(){
    ll n,k;cin >> n >>k;
    vl a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    ll res=0;
    rep(i,30){
        if((1LL<<i)&k){
            ll t=(1LL<<i);
            ll p=((k-t)|(t-1));
            ll sum=0;
            rep(j,n){
                if(p==(p|a[j]))sum+=b[j];
            }
            res=max(res,sum);
        }
    }
    ll tot=0;
    rep(j,n){
        if(k==(k|a[j]))tot+=b[j];
    }
    cout << max(res,tot) <<endl;
}   

Measured memory_bytes: 4844
#include <iostream>
using namespace std;
int main()
{
    int h, n, a, asum = 0;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        asum += a;
    }
    cout << (h <= asum ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x,y,tmp,r;

  scanf("%d%d",&x,&y);

  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }

  while(1){

    if (x%y==0) break;

    r=x%y;
    x=y;
    y=r;
  }

  /*while((r=x%y)!=0){
    x=y;
    y=r;
  }
  */
  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        cin >> x.at(i);
    }

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += min(K - x.at(i), x.at(i)) * 2;
    }

    cout << sum << endl;
}

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

int main(){
  int N,A;
  int x[50];
  cin>>N>>A;
  for(int i=0;i<N;i++){
    cin>>x[i];
    x[i]-=A;
  }
  map<int,ll> dp[51];
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    for(auto p:dp[i]){
      int j=p.first;
      ll c=p.second;
      dp[i+1][j]+=c;
      dp[i+1][j+x[i]]+=c;
    }
  }
  cout<<dp[N][0]-1<<endl;
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<string> s(n), ts(n);
	vector<int> p(n);
	for (int i = 0; i < n; i++)
		cin >> s.at(i) >> p.at(i);
	ts = s;
	sort(ts.begin(), ts.end());
	for (int i = 0; i < ts.size(); i++)
	{
		int t = 0;
		for (int j = 0; j < n; j++)
		{
			if (ts.at(i) == s.at(j) && t < p.at(j))
				t = p.at(j);
		}
		auto ite = std::find(p.begin(), p.end(), t);
		size_t index = std::distance(p.begin(), ite);
		p.at(index) = -1;
		cout << index + 1 << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  int ans[N];
  rep(i, N) {
    cin >> H[i];
    ans[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] < H[B - 1]) {
      ans[A - 1] = 0;
    } else if (H[A - 1] > H[B - 1]) {
      ans[B - 1] = 0;
    }

    else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }

  int sum_ = 0;
  rep(i, N) { sum_ += ans[i]; }
  cout << sum_ << endl;

  return 0;
}


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

int main(void){
    char s[100];
    scanf("%s",s);
    int len = strlen(s);
    int i,count=0;
    for(i=0;i<(len/2);i++){
        if(s[i] != s[len-1-i]){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

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

using namespace std;
int main(){
  string s; cin >> s;
  
  long long ans = 0;
  long long  last = s.size()-1;
  for(int i = s.size()-1; i >= 0; i--){
    if(s.at(i) == 'B'){
      ans += last - i;
      last--;
    } 
  }
  cout << ans << endl;
}



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

int main(){
	int prime[100005],n,pri[100005],nn=0;
	cin>>n;
	memset(prime,0,sizeof(prime));
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=100003;i++){
		if(!prime[i]){
			nn++;
			pri[nn]=i;
			for(int j=i+i;j<=100003;j+=i){
				prime[j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		int l,r;
		cin>>l>>r;
		int ll=1,rr=nn,sl;
		while(ll+1<rr){
			int mid=(ll+rr)/2;
			if(pri[mid]<=l){
				ll=mid;
			}else{
				rr=mid;
			}
		}
		sl=ll;
		ll=1;
		rr=nn;
		while(ll+1<rr){
			int mid=(ll+rr)/2;
			if(pri[mid]>=r){
				rr=mid;
			}else{
				ll=mid;
			}
		}
		//cout<<sl<<" "<<rr<<endl;
		sl=max(1,sl-3);
		rr=min(nn,rr+3);
		int s=0;
		for(int j=sl;j<=rr;j++){
			if(pri[j]>=l&&pri[j]<=r){
				//cout<<pri[j]<<" ";
				if(!prime[(pri[j]+1)/2]){
					s++;
				}
			}
		}
		cout<<s<<endl;
	}	
}


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


int main()
{
	int m, f, r;
	while (cin >> m >> f >> r, (m != -1 || f != -1 || r != -1)){
		if (m == -1 || f == -1){
			cout << "F" << endl;
		}
		else if (m + f >= 80){
			cout << "A" << endl;
		}
		else if (m + f >= 65){
			cout << "B" << endl;
		}
		else if (m + f >= 50){
			cout << "C" << endl;
		}
		else if (m + f >= 30){
			if (r >= 50){
				cout << "C" << endl;
			}
			else{
				cout << "D" << endl;
			}
		}
		else{
			cout << "F" << endl;
		}
	}
	
	return 0;
}

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

using namespace std;

int d[5] = {0,-1,0,1,0};

int main(){
	int h,w;
	cin >> h >> w;
	vector<string> b(50);
	for(int i=0;i<h;i++){
		cin >> b[i];
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int c=0;
			if(b[i][j] != '#') continue;
			for(int k=0;k<4;k++){
				if(i + d[k] < 0 || i + d[k] >= h) continue;
				if(j + d[k+1] < 0 || j + d[k+1] >= w) continue;
				if(b[i + d[k]][j + d[k+1]] == '#'){
					c++;
				}
			}
			if(c == 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
  int N; cin >> N;
  string s; cin >> s;
  int x = 0;
  int ans = 0;
  for ( int i = 0; i < s.length(); i++ ) {
    if ( s[i] == 'I' ) x++;
    else x--;
    ans = max(ans,x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static double dp[][];
	static int n;
	static int num[];
	static double dir[];
	static double val[];
	static int next[][];

	public static double f(int k, int bit) {
		if (0 < dp[k][bit]) {
			return dp[k][bit];
		}
		if ((bit | (1 << k)) == ((1 << n) - 1)) {
			return dp[k][bit] = 0;
		}

		double weight = 0;
		for (int i = 0; i < n; i++) {
			if (0 < (bit & (1 << i))) {
				weight += 20 * val[i];
			}
		}
		weight += 20 * val[k];

		double min = Double.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			if ((bit & (1 << i)) == 0 && i != k) {
				double s = f(i, bit | (1 << k));
				double t = 1.0 * Math.abs(dir[k] - dir[i]) * (70 + weight) / 2000;
				if (s + t < min) {
					min = s + t;
					next[k][bit] = i;
				}
			}
		}

		return dp[k][bit] = min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		num = new int[n];
		dir = new double[n];
		val = new double[n];
		dp = new double[n][1 << n];
		next = new int[n][1 << n];
		for (int i = 0; i < n; i++) {
			num[i] = sc.nextInt();
			dir[i] = sc.nextInt();
			val[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			Arrays.fill(dp[i], -1.0);
			Arrays.fill(next[i], -1);
		}

		for (int i = 0; i < n; i++) {
			f(i, 0);
		}

		int id = 0;
		for (int i = 0; i < n; i++) {
			if (0 <= dp[i][0] && dp[i][0] < dp[id][0]) {
				id = i;
			}
		}

		String s = "";
		int bit = 0;
		for (int i = 0; i < n; i++) {
			System.out.print(s + num[id]);
			int nid = next[id][bit];
			bit |= (1 << id);
			s = " ";
			id = nid;
		}
		System.out.println();
	}
}

Measured memory_bytes: 28256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<algorithm>
using namespace std;
int main()
{
     int a,b,c;
     cin >> a >> b >> c;
     if(a > b)swap(a,b);

     if(a <= c && c <= b)cout << "Yes" << endl;
     else cout << "No" <<endl;
     return 0;
}

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

int main(){
  int n, m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int> > battle(m);
  int brk = 0, cnt = 0;
  for(int i = 0; i < m; i++){
    std::cin >> battle[i].second >> battle[i].first;
  }
  std::sort(battle.begin(), battle.end());

  for(int i = 0; i < m; i++){
    if(battle[i].second > brk){
      brk = battle[i].first - 1;
      cnt++;
    }
  }
  std::cout << cnt << std::endl;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i,h) cin >> c[i];
  int ans=0;
  rep(is, 1<<h)rep(js, 1<<w){
    int b=0;
    rep(i,h)rep(j,w){
      if(is>>i&1) continue;
      if(js>>j&1) continue;
      if(c[i][j] == '#')b++;
    }
    if(b==k)ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,a,b,sum=0;
  cin >> n;
  int data[n+1];  
  for(int i=0;i<n;i++){
    cin >> data[i];
  }

  cin >> t;
  for(int i=0;i<t;i++){
    cin >> a >> b;
    sum=0;
    for(int j=0;j<n;j++){
      if(j == a-1){
	sum+=b;
      }else{
	sum+=data[j];
      }
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
const int INF = 0x3f3f3f3f;
using namespace std;

int T[50010];
int C[25];

int n,m;
int main() {
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>C[i];
	}
	for(int i=0;i<=50010;i++){
		T[i] = INF;
	}
	T[0] = 0;
	for(int i=1;i<=m;i++){
		for(int j=0;j+C[i]<=n;j++){
			T[j+C[i]] = min(T[j+C[i]], T[j]+1);
		}
	}
	cout<<T[n]<<endl;
	return 0;
}



Measured memory_bytes: 3284
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll> & v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}
ll dp[3][100010];
void solv() {
	
	string s;
	cin >> s;
	string abc = "ABC";

	ll qc = 1;
	if (s[0] == 'A') {
		dp[0][0] = 1;
	}
	else if (s[0] == '?') {
		dp[0][0] = 1;
		qc = 3;
	}

	for (size_t i = 1; i < s.size(); i++)
	{
		bool b = s[i] == '?';
		for (size_t j = 0; j < 3; j++)
		{
			dp[j][i] = dp[j][i - 1] * (b ? 3LL : 1LL);
			dp[j][i] %= INF;
		}

		if (b || s[i] == 'A') {
			dp[0][i] += qc;
			dp[0][i] %= INF;
		}
		if(b || s[i] == 'B'){
			dp[1][i] += dp[0][i - 1];
			dp[1][i] %= INF;
		}
		if (b || s[i] == 'C'){
			dp[2][i] += dp[1][i - 1];
			dp[2][i] %= INF;
		}
		if (b) {
			qc *= 3;
			qc %= INF;
		}
	}


	cout << dp[2][s.size() - 1] << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 4608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Test
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        for(int i = 3; i <= n; ++i)
        {
            if(i % 3 == 0 || i.ToString().Contains("3"))
            {
                Console.Write(" " + i);
            }
        }
        Console.WriteLine();
        return ;
    }
}


Measured memory_bytes: 17948
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <queue>
using namespace std;
int main(void){
	int m,f,b;
	cin>>m>>f>>b;
	if(m+f<b) cout<<"NA"<<endl;
	else if(m>=b) cout<<"0"<<endl;
	else cout<<b-m<<endl;
	return 0;
}



Measured memory_bytes: 3092
n = int(input())
a = list(map(int, input().split()))

dp = [[0] * (n + 1) for _ in range(n + 1)]

for i in range(n)[::-1]:
    for j in range(n + 1):
        if i >= j:
            continue
        dp[i][j] = max(a[j - 1] - dp[i][j - 1], a[i] - dp[i + 1][j])

print(dp[0][n])


Measured memory_bytes: 114012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld",&n)
#define sff(n,m) scanf("%lld %lld",&n,&m)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PLL pair<ll,ll>
#define mod 998244353
#define mx 100002
#define FILE freopen("input.txt","w",stdin)

vector<PLL>v;

int main()
{
ll n,m;
cin>>n>>m;

ll a,b;

for(ll i = 1;i<=n;i++)
{
  cin>>a>>b;
  v.push_back({a,b});
}

sort(v.begin(),v.end());

priority_queue<ll>pq;

ll i = 0;
ll ans = 0;

for(ll j = v.size()-1;j>=0;j--)
{
  while(v[i].first<=m-j&&i<v.size())
  {
    pq.push(v[i].second);
    i++;
  }

  if(!pq.empty()){
     ans+=pq.top();
     pq.pop();
  }
}

cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3568
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n) + str(X % n)
    return str(X % n)


N, A, B, C = map(int, input().split(" "))
bamboos = [int(input()) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    now = Base_10_to_n(i, 4).zfill(N)
    length = [0, 0, 0, 0]
    cost = 0
    for j, c in enumerate(now):
        for k, num in enumerate("0123"):
            if c == num:
                length[k] += bamboos[j]
                break
    if length[0]*length[1]*length[2] == 0:
        continue
    cost += 10 * (now.count('0')-1)
    cost += 10 * (now.count('1')-1)
    cost += 10 * (now.count('2')-1)
    cost += abs(A-length[0])
    cost += abs(B-length[1])
    cost += abs(C-length[2])
    ans = min(cost, ans)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define lowbit(x) x & -x
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=3e3+5;
int mp[N][N];
ll dp[N][N][5];
int main(){
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    int n,m,kk;
    scanf("%d%d%d",&n,&m,&kk);
    for(int i=1;i<=kk;i++){
        int x,y,val;
        scanf("%d%d%d",&x,&y,&val);
        mp[x][y]=val;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j][0]=dp[i][j-1][0];
            for(int k=0;k<=3;k++){
                dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+mp[i][j]);
            }
            for(int k=1;k<=3;k++){
                dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
                dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+mp[i][j]);
                
            }
        }
    }
    
    printf("%lld\n",max(max(dp[n][m][0],dp[n][m][1]),max(dp[n][m][2],dp[n][m][3])));
    return 0;
}


Measured memory_bytes: 391160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,ans=0;
  cin >> n >> a >> b;
  for(int i=0;i<=n;i++){
    int m=i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10;
    if(m>=a&&m<=b){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5+10;
int num[maxn];
bool vis[maxn];
vector<int>Edge[maxn];
void addEdge(int a,int b)
{
    Edge[a].push_back(b);
    Edge[b].push_back(a);
}
void bfs(int u)
{
    vis[u] = true;
    queue<int>q;
    q.push(u);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(int i = 0;i<Edge[v].size();++i)
        {
            int j = Edge[v][i];
            if(!vis[j])
            {
                vis[j] = 1;
                num[j] = v;
                q.push(j);
            }
        }
    }
    return ;
}
int main()
{

    int n,m;
    scanf("%d %d",&n,&m);
    memset(num,-1,sizeof(num));
    memset(vis,false,sizeof(vis));
    num[1] = 0;
    int a,b;
    while(m--)
    {
        scanf("%d %d",&a,&b);
        addEdge(a,b);
    }
//    for(int i = 1;i<=n;++i)
//    {
//        printf("%d: ",i);
//        for(int j = 0;j<Edge[i].size();++j)
//            printf("%d ",Edge[i][j]);
//        printf("\n");
//    }
    vis[1] = true;
    bfs(1);
    bool flag = false;
    for(int i = 2;i<=n;++i)
    {
        if(num[i]==-1)
        {
            flag  =true;
            break;
        }
    }
    if(flag)
        printf("No\n");
    else
    {
        printf("Yes\n");
        for(int i = 2;i<=n;++i)
        {
            printf("%d\n",num[i]);
        }
    }
    return 0;
}


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

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}
ll a, b, c, x, y, mem, ans;

int main(){
    cin >> a >> b >> c >> x >> y;

    mem = maxll(x, y) * 2 * c;
    ans = minll(mem, a*x + b*y);
    if(x > y){
        ans = minll(ans, c*2*y + a*(x-y));
    }
    else{
        ans = minll(ans, c*2*x + b*(y-x));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, seq, func="min"):
        if func=="min":
            self.f = min
            self.e = float('inf')
        if func=="max":
            self.f = max
            self.e = -float('inf')
        if func=="gcd":
            self.f = gcd
            self.e = 0
        self._n = len(seq)
        self.n_seg = 2**(self._n-1).bit_length()
        self.seg = [self.e]*2*self.n_seg
        
        for i in range(self._n):
            self.seg[self.n_seg+i-1] = seq[i]
            
        for i in range(self.n_seg-2, -1, -1):
            self.seg[i] = self.f(self.seg[2*i+1], self.seg[2*i+2])
        
    def update(k, val):
        k += self.n_seg -1
        self.seg[k] = val
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.f(self.seg[k*2+1], self.seg[k*2+2])
        
    def query(self, a, b):
        if b<=a:
            return self.e
        a += self.n_seg-1
        b += self.n_seg-2
        res = self.e
        while b-a>1:
            if a&1==0:
                res = self.f(res, self.seg[a])
            if b&1==1:
                res = self.f(res, self.seg[b])
                b -= 1
            a = a//2
            b = (b-1)//2
        if a==b:
            res = self.f(res, self.seg[a])
        else:
            res = self.f(self.f(res, self.seg[a]), self.seg[b])
        return res
    
    def __repr__(self):
        ret = str(self.seg[self._n-1:])
        return ret

def gcd(a, b):
    if b>a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

if __name__=="__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A_seg = SegmentTree(A, func="gcd")
    ans = -1
    for i in range(N):
        ans = max(ans, gcd(A_seg.query(0, i), A_seg.query(i+1, N)))
    print(ans)

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

int main(){

   string S; cin >> S;
   int num_zero = 0,num_one = 0;
   int len = S.size();
   for(int i=0;i<len;i++){
       if(S[i] == '0') num_zero++;
       else num_one++;
   }
   cout << 2 * min(num_one,num_zero) << endl;
}

Measured memory_bytes: 3764
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int k;

const int INF = 10000000;
int dist[100000+10];

struct K {
  int v, c;
};
bool operator>(const K& k1, const K& k2) {
  return k1.c > k2.c;
}

int go(void) {
  REP(i, 100000+10) {
    dist[i] = INF;
  }
  priority_queue<K, vector<K>, greater<K> > q;
  for(int i = 1; i <= 9; ++i) {
    q.push((K){i, i});
    dist[i] = i;
  }
  while(!q.empty()) {
    K cur = q.top(); q.pop();
    if(dist[cur.v] < cur.c) {
      continue;
    }
    if(cur.v == 0) {
      break;
    }
    REP(i, 2) {
      K next = {(cur.v*10+i)%k, cur.c + i};
      if(next.c < dist[next.v]) {
        q.push(next);
        dist[next.v] = next.c;
      }
    }
  }
  return dist[0];
}

int main(void) {
  while(~scanf("%d", &k)) {
    int res = go();
    printf("%d\n", res);
  }
  return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

class BIT{
public:
	vector<int> bit;
	int M;
	// 1-index
	BIT(int M):
		bit(vector<int>(M+1, 0)), M(M) {}

	int sum(int i) {
		if (!i) return 0;
		return bit[i] + sum(i-(i&-i));
	}

	void add(int i, int x) {
		if (i > M) return;
		bit[i] += x;
		add(i+(i&-i), x);
	}
};



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

	while(1){
		ll n,m;
		cin >> n >> m;
		if(n==0&&m==0)break;
		map<ll,ll> hcount;
		BIT H(n),W(m);
		ll ans = 0;
		FOR(i,0,n){
			ll k;
			cin >> k;
			H.add(i+1,k);
		}
		FOR(i,0,m){
			ll k;
			cin >> k;
			W.add(i+1,k);
		}
		FOR(i,0,n+1){
			FOR(j,0,i){
				ll k = H.sum(i)-H.sum(j);
				hcount[k]++;
			}
		}
		FOR(i,0,m+1){
			FOR(j,0,i){
				ll k = W.sum(i)-W.sum(j);
				ans += hcount[k];
			}
		}
		cout << ans << endl;
	}
}


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

#define i64 long long int
#define ran 202202

int n;
int a[ran];
int s[ran];

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		s[a[i]]++;
	}
	i64 ans = 0;
	for(int i=0;i<ran;i++)
		ans += 1LL*s[i]*(s[i]-1)/2;
	
	for(int i=0;i<n;i++) {
		printf("%lld\n", ans - (s[a[i]]-1));
	}
	
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,P,ans=1; cin>>N>>P;
  vector<ll> A;
  for(int i=2; i<=P/i; i++){
    if(P%i==0){
      A.push_back(i);
      P/=i, i--;
    }
  }
  A.push_back(P);
  while(A.size()>=N){
    auto IT=lower_bound(A.begin(), A.end(), A[0]+1);
    ll z=IT-A.begin();
    while(z>=N){
      z-=N;
      ans*=A[0];
    }
    A.erase(A.begin(), IT);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readints():return list(map(int,readline().split()))

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

dist = [10**10]*(h*w)

a = [[]for i in range(2)]
i = 0
a[i].append(start)
dist[start] = 0

while a[0] or a[1]:
    p = a[i].pop()
    y = p//w
    x = p%w
    for dy in range(-2,3):
        for dx in range(-2,3):
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                q = (y+dy)*w + x+dx
                if abs(dy)+abs(dx)==1:
                    if dist[q]>dist[p]:
                        a[i].append(q)
                        dist[q] = dist[p]
                else:
                    if dist[q]>dist[p]+1:
                        a[i-1].append(q)
                        dist[q] = dist[p] + 1
    if not a[i]:
        i = [1,0][i]


print(-1 if dist[goal]==10**10 else dist[goal])


Measured memory_bytes: 83972
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int A[10],k;
    bool x=true;
    REP(i,5) cin>>A[i];
    cin>>k;
    REP(i,4){
        FOR(j,i+1,5) {
            if(abs(A[i]-A[j])>k) x=false;
        }
    }
    if(x) cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
}

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

long long a,b,c,d;

int main()
{
	cin>>a>>b>>c>>d;
	long long ans=a*c;
	ans=max(ans,a*d);
	ans=max(ans,b*d);
	ans=max(ans,b*c);
	cout<<ans;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL ll[400005],rr[400005];
LL stk[400005],tp = 0;
LL n,a[400005],tot = 0;

int main(){
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	for(LL i = 1;i <= n;i ++){
		ll[i] = 0;
		rr[i] = n + 1;
	}
	
	tp = 0;
	for(LL i = 1;i <= n;i ++){
		while(tp && a[stk[tp]] > a[i]){
			rr[stk[tp]] = i;
			tp --;
		}
		stk[++ tp] = i;
	}
	
	tp = 0;
	for(LL i = n;i >= 1;i --){
		while(tp && a[stk[tp]] > a[i]){
			ll[stk[tp]] = i;
			tp --;
		}
		stk[++ tp] = i;
	}
	
	for(LL i = 1;i <= n;i ++) tot += (rr[i] - i) * (i - ll[i]) * a[i];
	cout << tot << endl;
	return 0;
}
//

Measured memory_bytes: 12032
ABCXY = list(int(i) for i in input().split())

XY = []
XY.append(ABCXY[3])
XY.append(ABCXY[4])

ans = 0
if 2*ABCXY[2] < ABCXY[0] + ABCXY[1]:
    ans += min(XY)*2*ABCXY[2]
    if XY[0] > XY[1]:
        if ABCXY[0] < 2*ABCXY[2]:
            ans += (XY[0]-XY[1])*ABCXY[0]
        else:
            ans += (XY[0]-XY[1])*ABCXY[2]*2
    else:
        if ABCXY[1] < 2*ABCXY[2]:
            ans += (XY[1]-XY[0])*ABCXY[1]
        else:
            ans += (XY[1]-XY[0])*ABCXY[2]*2
else:
    ans += ABCXY[0]*XY[0] + ABCXY[1]*XY[1]
print(ans)


Measured memory_bytes: 3064
def fn(n)
  res = 1
  n.step(1, -2) do |i|
    break if n < 2
    res *= i
  end
  res
end

def count_r(n)
  rev = n.to_s.reverse
  res = 0
  rev.chars.each { |i| break if i != '0'; res += 1 }
  res
end

n = gets.to_i
# prepared_res = count_r(fn(n))
res = 0
if n.odd?
  res = 0
else 
  res += n / 10
  n /= 10
  while n >= 5
    res += n / 5
    n /= 5
  end
end
puts res
# puts prepared_res
# puts count_r  fn(10)
# puts count_r  fn(20)
# puts count_r  fn(30)
# puts count_r  fn(40)
# puts count_r  fn(50)
# puts count_r  fn(80)
# puts count_r  fn(96)
# puts count_r  fn(100)
# puts count_r  fn(110)
# puts count_r  fn(140)
# puts count_r  fn(150)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long A;
  string B;
  cin>>A>>B;
  long s=0;
  s+=A*(B[0]-'0')*100;
  //cout<<s<<endl;
  s+=A*(B[2]-'0')*10;
  s+=A*(B[3]-'0');
  cout<<s/100<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
    int d,ad,sum=0,i,td,vac;
    scanf("%d %d",&d,&ad);
    for(i=1;i<=ad;i++)
    {
        scanf("%d",&td);
        sum=sum+td;
    }
    if(sum<=d)
        printf("%d\n",d-sum);
    else
        printf("-1\n");
    return 0;
}


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

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

	long long ans = 0;
	for( int a = 1; a <= K; a++ ) {
		for( int b = 1; b <= K; b++ ) {
			for( int c = 1; c <= K; c++ ) {
				ans += __gcd( a, __gcd( b, c ) );
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;

int dp[2003][2003] , predp[2003][2003];

int mul(int a , int b){
  int x = (a*b) % mod;
  return x;
}
signed main(){
  fast;
 int n , k;
  cin >> n >> k;
  int max_balls = max(k   , n-k);
  
 dp[0][0] = 1;
 for(int i = 0 ; i<= (max_balls + 1) ; i++)
     predp[0][i] = 1;


  for(int i = 1 ; i<=(k + 1) ; i++){
    for(int j = i ; j<= (max_balls + 1) ; j++){
      dp[i][j] = predp[i-1][j-1] ;
      // cout << i << " "<< j << " "<<dp[i][j] << endl;
    }
    
    for(int j = i ; j<= (max_balls + 1) ; j++){
      if(j-1 >= i)
      predp[i][j] = (predp[i][j-1] + dp[i][j] ) % mod;
      else
        predp[i][j] = dp[i][j];
    }
  }


     int ans;
  for(int i = 1 ; i<=k ; i++){
      ans = mul(dp[i][k]  , dp[i-1][n-k]);
      ans += 2 * mul(dp[i][k]  ,  dp[i][n-k]) ;
      ans %= mod;
      ans +=  mul(dp[i][k] ,dp[i+1][n-k]);
      ans %= mod;
      cout << ans << endl;
  }
    
}	

Measured memory_bytes: 62080
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                sum += d[i] * d[j];
            }
        }
        System.out.println(sum);
    }

}



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

using namespace std;

int main() {
  string S;
  int Q;

  cin >> S;
  cin >> Q;

  stringstream left;
  stringstream right;

  bool reversed = false;
  for (int q = 0; q < Q; q++) {
    int T;
    cin >> T;
    if (T == 1) {
      reversed = !reversed;
    } else {
      int F;
      char C;
      cin >> F >> C;

      if (reversed) {
        if (F == 1) {
          F = 2;
        } else {
          F = 1;
        }
      }

      if (F == 1) {
        left << C;
      } else {
        right << C;
      }
    }
  }

  string sleft = reversed ? right.str() : left.str();
  string sright = reversed ? left.str() : right.str();

  reverse(sleft.begin(), sleft.end());
  if (reversed) {
    reverse(S.begin(), S.end());
  }

  cout << sleft << S << sright << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int N,X;
    cin>>N>>X;
    vi L(N);
    F0R(i,N){
        cin>>L[i];
    }
    int sum=0;
    F0R(i,N){
        sum+=L[i];
        if(sum>X){
            out(i+1);
            return;
        }
    }
    out(N+1);
    return ;
}

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

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


int m;
int C[10000];
int L[10000];

void input(const int n){
	m=0;
	cin >> C[m];
	L[m] = 1;
	for(int i=1; i<n; ++i){
		int c;
		cin >> c;
		
		if(C[m] == c){
			++L[m];
		}else{
			++m;
			C[m] = c;
			L[m] = 1;
		}
	}
	++m;
}

int check(int low, int hih){
	int ret = 0;
	if(0 <= low && L[low] >= 4 && (hih>=m || C[low] != C[hih])){
		ret += L[low];
		low --;
	}
	if( hih<m && L[hih]>=4 && (low<0 || C[low] != C[hih])){
		ret += L[hih];
		hih ++;
	}
	while(0 <= low && hih < m && C[low] == C[hih] && L[low] + L[hih] >= 4){
		ret += L[low] + L[hih];
		low--;
		hih++;
	}
	return ret;
}

int solve(){
	int ret = 0;
	for(int i=0; i<m; ++i){
		L[i]--;
		if(i+1 < m){
			L[i+1]++;
			if(L[i]>0){
				ret = max(ret, check(i  , i+1));
			}else{
				ret = max(ret, check(i-1, i+1));
			}
			L[i+1]--;
		}
		if(i-1 >= 0){
			L[i-1]++;
			if(L[i]>0){
				ret = max(ret, check(i-1, i));
			}else{
				ret = max(ret, check(i-1, i+1));
			}
			L[i-1]--;
		}
		L[i]++;
	}
	return ret;
}

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		input(n);
		cout << (n - solve()) << endl;
	}
}


Measured memory_bytes: 3176
#abcd = list(map(int,input().split()))
abcd = input()
ans = ""
#print(abcd[0])

# tmp = int(abcd[0]) + int(abcd[1])
# print(tmp)

if int(abcd[0]) + int(abcd[1]) + int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "+" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) + int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "+" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) - int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "-" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) + int(abcd[1]) - int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "+" + abcd[1] + "-" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) + int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "+" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) + int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "+" + abcd[2] + "-" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) - int(abcd[2]) + int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "-" + abcd[2] + "+" + abcd[3] + "=7"
elif int(abcd[0]) - int(abcd[1]) - int(abcd[2]) - int(abcd[3]) == 7:
    ans = abcd[0] + "-" + abcd[1] + "-" + abcd[2] + "-" + abcd[3] + "=7"

print(ans)


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

int main(void)
{
    int n, m;
    int A[200000] = {},B[200000] = {};
    int a, b;
    cin >> n >> m;
    int i = 0;
    int j = 0;
    int k = 0;
    int h;
    int flag = 0;
    for(i = 0; i < m; i++){
        cin >> a >> b;        
        if(a == 1){
            A[b] = 1;
            j++;
        }
        if(b == n){
            B[a] = 1;
            k++;
        }
    }


    int counter = 0;
    i = 0;
    while(counter != j){
        while(1){
            if(A[i] == 1){
                if(B[i] == 1){
                    flag = 1;
                    break;
                }
            counter++;
            i++;
            break;
            }
        i++;
        }
        if(flag == 1){break;}

    }
    
    if(flag == 1){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
    

    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	ll N;
	
	cin >> N;
	
	double sr = sqrt(N);
	ll sr2 = (ll) sr;

	if (N == sr2 * sr2) {
		cout << sr2 - 1 + sr2 - 1 << endl;
	} else {
		for (ll i = sr2; i > 0; i--) {
			if (N % i == 0) {
				ll m = N / i;
				cout << i - 1 + m - 1 << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>

using namespace std;

int main()
{
	double d, e;
	double mp[105][105];
	int i, j;
	double dis;
	double dd;
	for (i = 0; i < 101; i++){
		for (j = 0; j < 101; j++){
			mp[i][j] = sqrt(pow(i, 2.0) + pow(j, 2.0));
		}
	}
	
	i = j = 0;
	while(scanf("%lf %lf", &d, &e), d != 0 && e != 0){
		dis = 1000000;
		for (i = 0; i + j <= d; i++){
			for (j = 0; i + j <= d; j++){
				if (i + j == d){
				if (mp[i][j] > e) dd = mp[i][j] - e;
				else dd = e - mp[i][j];
				//printf(" %lf %d %d\n", mp[i][j], i, j);
				if (dis > dd) dis = dd;
				}
			}
			j = 0;
		}
		
		printf("%lf\n", dis);
	}
}

Measured memory_bytes: 2844