akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	char s1[n], s2[n];
	scanf(" %s %s", s1, s2);
	long long num=1;
	int prev=-1;
	for (int i=0; i<n; i++) {
		if (s1[i]==s2[i]) {
			if (prev==-1) num*=3;
			else if (prev==0) num*=2;
			prev=0;
		}
		else {
			if (prev==-1) num*=6;
			else if (prev==0) num*=2;
			else if (prev==1) num*=3;
			prev=1;
			i++;
		}
		num%=MOD;
	}
	printf("%lld\n", num);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define Mod 1000000007

#define INF 1ll<<29

int MAX_V=1010101;
struct edge{int to,cost;};
typedef pair<int,int> P;
int d[501010];
int V;
vector<edge> G[501010];

edge makeedge(int t,int c){
    edge e;
    e.to=t;
    e.cost=c;
    return e;
}

void addedge(int s,int t,int c){
    G[s].push_back(makeedge(t,c));
    //G[t].push_back(makeedge(s,c)); //双方向
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s)); 

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

ll n,m;

int main(){
  ll i,j;
  V=501010;
  cin>>n>>m;
  for(i=0;i<m;i++){
    ll u,v;
    cin>>u>>v;
    u--;
    v--;
    u*=3;
    v*=3;

    addedge(u,v+1,1);
    addedge(u+1,v+2,1);
    addedge(u+2,v,1);
  }
  ll s,t;
  cin>>s>>t;
  s--;
  t--;
  s*=3;
  t*=3;
  dijkstra(s);

  if(d[t]<INF){
    cout<<d[t]/3<<endl;
  }
  else cout<<-1<<endl;


  
  return 0;  
}

Measured memory_bytes: 23296
function main(input) {
	const args = input.split(' ');
	const N = parseInt(args[0], 10);
	const A = parseInt(args[1], 10);
	const B = parseInt(args[2], 10);

	var result = 0;

	for(var i = 1; i <= N; i++) {
		var digitsum = i.toString().split('').map((c) => parseInt(c, 10)).reduce((p, c) => p + c, 0);
		if(A <= digitsum && digitsum <= B) {
			result += i;
		}
	}
	console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11232
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

int n,m;
#define N 100010
int par[N];
int rnk[N];

void init(int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rnk[x] < rnk[y]) par[x] = y;
    else{
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x,int y){
    return find(x) == find(y);
}
signed main(){

    cin >> n >> m;
    init(n);
    vector<int> lan[100010];
    rep(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int l;
            cin >> l;
            int s = lan[l].size();
            if(s >= 1){
                unite(lan[l][s-1],i);
            }
            lan[l].pb(i);
        }
    }
    int p = find(0);
    for(int i = 1; i<n;i++){
        if(find(i) != p){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    

    
    
    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://abc061.contest.atcoder.jp/tasks/abc061_d


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

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

  string s;
  int k;
  cin >> s >> k;
  set<string> subs;
  for (size_t i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= k; ++j) {
      if (s.size() < i + j) break;
      subs.insert(string(&s[i], j));
    }
  }
  auto ans = subs.begin();
  advance(ans, k - 1);
  cout << *ans << "\n";
}


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

using namespace std;

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

  int b = 0;
  int a = 0;
  int ba = 0;
  int count = 0;

  for(int n=0; n<N; n++){
    string s;
    cin >> s;
    if(s[0] == 'B' && s[s.length()-1] == 'A'){
      ba++;
    }else{
      if(s[0] == 'B'){
        b++;
      }else if(s[s.length()-1] == 'A'){
        a++;
      }
    }

    for(int i=0; i<s.length()-1; i++){
      if(s[i]=='A' && s[i+1]=='B') count++;
    }
  }
  //cout << "count:"<<count<< "\nba:"<<ba<<"\nb:"<<b<<"\na:"<<a << "\n";

  int min = 0;
  if(a<b){
    min = a;
  }else{
    min = b;
  }

  if(ba==0){
    count += min;
  }else{
    if( a>0 || b>0){
      count += ba+min;
    }else{
      count += ba-1;
    }
  }

  /*
  int min;
  if(ba<a && ba<b){
    min = ba;
  }else{
    if(a<b){
      min = a;
    }else{
      min = b;
    }
  }
  if(min >0) count += min+1;
  a-=min;
  b-=min;
  ba-=min;
  if(a<b){
    min = a;
  }else{
    min = b;
  }
  count += min;
  if(a!=b && ba >= 1) count++;
  if(ba>=2) count += ba-1;

  */

  cout << count;

  return 0;
}


Measured memory_bytes: 256
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	int[] arr;
	int[] costs;
	int[][] books;
	int inf = Integer.MAX_VALUE;
	int res;
	int n, m, x;
	private void run_case() {
		n = reader.ni();
		m = reader.ni();
		x = reader.ni();

		arr = new int[m+5];
		Arrays.fill(arr, x);
		costs = new int[n+5];
		books = new int[n+5][m+5];

		for (int i=1; i<=n; i++) {
			costs[i] = reader.ni();
			for (int j=1; j<=m; j++) {
				books[i][j] = reader.ni();
			}
		}

		res = inf;
		dfs(1, 0);

		if (res == inf) res = -1;
		out.println(res);

		return;
	}

	private void dfs(int idx, int sum) {
		if (check()) {
			res = Math.min(res, sum);
			return;
		}
		for (int i=idx; i<=n; i++) {
			for (int j=1; j<=m; j++) arr[j] -= books[i][j];
			dfs(i+1, sum + costs[i]);
			for (int j=1; j<=m; j++) arr[j] += books[i][j];
		}
		return;
	}

	private boolean check() {
		for (int i=1; i<=m; i++) {
			if (arr[i] > 0) return false;
		}
		return true;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 34372
#include<stdio.h>
int main()
{
 int a;
 scanf("%d",&a);
  int x[]= {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};

  printf("%d",x[a-1]);
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[22][22]={0};
int get1(int a){
    while(a>=10)
        a/=10;
    return a;
}
int main()
{
    int n;int ans= 0;
    cin >> n;
    for(int i=1;i<=n;i++){
        
            a[get1(i)][i%10]++;
    }
    for(int i=1;i<=n;i++){
        if(i%10)
            ans+=a[i%10][get1(i)];
    }

//    for(int i=1;i<10;i++){
//        for(int j=1;j<10;j++){
//            ans+=a[i][j]+a[j][i];
//        }
//    }
    cout <<ans <<endl;
    return 0;
}

//112 111 111 111 111 111 111 111 111
//13 14 13 13 13 13 13 13 13
//11 11 12 11 11 11 11 11 11
//11 11 11 12 11 11 11 11 11
//11 11 11 11 12 11 11 11 11
//11 11 11 11 11 12 11 11 11
//11 11 11 11 11 11 12 11 11
//11 11 11 11 11 11 11 12 11
//11 11 11 11 11 11 11 11 12
//40812




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

int main (){
  string s;
  cin >> s;
  int max=0;
  int ans=0;
  for(int i=0;i<3;i++)
  {
    if(s.at(i)=='R')
    {
      ans++;
      if(max<ans){
        max=ans;
      }
    }
    if(s.at(i)=='S')
    {
      ans=0;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int M = 55555;
		  int N = sc.nextInt();
		  sc.close();
		  int[] prime = new int[M + 1];
		  prime[0] = 1;
		  prime[1] = 1;
		  for(int i = 2; i <= Math.sqrt(M); i++) {
			  if(prime[i] == 0) {
				  int j = i + i;
				  while(j <= M) {
					  prime[j] = 1;
					  j += i;
				  }
			  }
		  }
	      
		  String answer = "";
		  int count = N;
		  
		  for(int i = 2; i <= M; i++) {
			  if(prime[i] == 0 && i % 5 == 1) {
				  answer += (i + " ");
				  count--;
			  }
			  if(count == 0) {
				  break;
			  }
		  }
		  
	    	  System.out.println(answer);  
	      System.exit(0);
	    }
}

Measured memory_bytes: 19924
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=1e6+5;
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0');
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
#endif
}
const int mo=1e9+7;
int n,inv[N],mc[N];
void input()
{
	n=read<int>();
}
ll power(ll x,int y)
{
	int res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
void init()
{
	mc[0]=inv[0]=1;
	For(i,1,n)mc[i]=(ll)mc[i-1]*i%mo;
	inv[n]=power(mc[n],mo-2);
	Fordown(i,n-1,1)inv[i]=(ll)inv[i+1]*(i+1)%mo;
}
int C(int n,int m)
{
	if(n<m)return 0;
	return (ll)mc[n]*inv[m]%mo*inv[n-m]%mo;
}
int f[N];
void work()
{
	int ans=0;
	int d=(n+1)/2;
	For(i,d,n-1)f[i]=1ll*C(i-1,n-i-1)*mc[i]%mo*mc[n-i-1]%mo;
	//For(i,d,n-1)cout<<i<<' '<<f[i]<<endl;
	Fordown(i,n-1,d)f[i]=(f[i]-f[i-1]+mo)%mo;
	//For(i,d,n-1)cout<<i<<' '<<f[i]<<endl;
	For(i,d,n-1)ans=(ans+1ll*f[i]*i%mo)%mo;
	write(ans,'\n');
}
int main()
{
	
	input();
	init();
	work();
	return 0;
}


Measured memory_bytes: 9984
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

a,b,k=map(int,input().split())
g=gcd(a,b)
cnt=0
for i in range(g,0,-1):
    if g%i==0: cnt+=1
    if cnt==k:
        print(i)
        break

Measured memory_bytes: 9124
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
n, m = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(n)
ans = 0

for i in range(m):
    x, y = map(int, input().split())
    uf.union(x - 1, y - 1)

for i in range(n):
    if uf.same(i, p[i] - 1):
        ans += 1

print(ans)


Measured memory_bytes: 13940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
ll inf=1e+9+3;
int main(void){
    int n,m;cin>>n>>m;
    vector<vector<pair<int,int>>> t(n);
    rep(i,m){
        int l,r,d;cin>>l>>r>>d;l--;r--;
        t[l].push_back({r,d});
        t[r].push_back({l,-d});
    }
    vector<ll> mp(n,-inf);
    rep(i,n){
        if(mp[i]!=-inf)continue;
        if(t[i].size()==0)continue;
        mp[i]=0;
        queue<ll> que;
        que.push(i);
        while(que.size()){
            ll l=que.front();que.pop();
            ll x=mp[l];
            rep(j,t[l].size()){
                ll r=t[l][j].first,d=t[l][j].second;
                if(mp[r]==-inf){
                    que.push(r);
                    mp[r]=x+d;
                }else{
                    ll rx=mp[r];
                    if(rx!=x+d){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int D;
	cin >> D;
	string eve;
	rep(i, 25 - D) {
		eve += " Eve";
	}
	cout << "Christmas" + eve<< endl;
	return 0;
}

Measured memory_bytes: 256
// Selection sort
#include <stdio.h>
#include <stdlib.h>

int main() {
  int *a;
  int i, j, n, tmp;
  int cnt = 0;
  int min;

  // input the size of an array
  scanf("%d", &n);
  a = (int *)malloc(n * sizeof(int));

  // input the number of array
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  // sorting
  for(i = 0; i < n; i++) {
    min = i;
    for(j = i; j < n; j++) {
      if(a[j] < a[min]) {
	min = j;
      }
    }
    // swap a[i] and a[min]
    if(a[i] > a[min]){
      cnt++;
      tmp = a[i];
      a[i] = a[min];
      a[min] = tmp;
    }
  }

  // output
  for(i = 0; i < n; i++) {
    printf("%d", a[i]);
    if(i != n-1) printf(" ");
    else printf("\n");
  }
  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 2064
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
		int N = int.Parse(Console.ReadLine());
		int[] x = new int[N];
		int[] y = new int[N];
		for (int i = 0; i < N; i++)
		{
			string[] input = Console.ReadLine().Split(' ');
			x[i] = int.Parse(input[0]);
			y[i] = int.Parse(input[1]);

		}

		int ans = 1;
		if (N == 1) { Console.WriteLine(ans); }
		else
		{

			List<Tuple<int, int>> list = new List<Tuple<int, int>>();


			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < N; j++)
				{
					if (i == j) { continue; }
					else
					{
						list.Add(new Tuple<int,int>(x[i]- x[j], y[i] - y[j]) );
					}
				}
			}
			List<int> cnt = new List<int>();
			for (int i = 0; i < list.Count; i++)
			{
				int d = 0;
				for (int j = 0; j < N; j++)
				{
                   for(int k = 0; k < N; k++)
					{
						if (list[i].Item1 == x[j] - x[k] && list[i].Item2==y[j]-y[k])
						{
							d++;
						}
					}
				}
				cnt.Add(d);

			
			}
			cnt.Sort();
			cnt.Reverse();
			Console.WriteLine(N-cnt[0]);
		}
        

		
	
	}
}




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

using namespace std;

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

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	ll dx = x2-x1, dy = y2-y1;
	cout << (x2-dy) << " " << (y2+dx) << " " << (x1-dy) << " " << (y1+dx) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int N, K;
ll height[305];
ll dp[305][305]; //dp[x][y], x -> rightmost element, y -> # of elements
ll INF = 0x3f3f3f3f3f3f3f3f;
int main() {
    cin >> N >> K;
    for (int i=1; i<=N; i++){
        scanf("%lld", &height[i]);
    }
    memset(dp, INF, sizeof(dp));
    for (int i=1; i<=N; i++) {
        dp[i][0] = 0;
        dp[i][1] = height[i];
    }
    for (int x=1; x<=N; x++){
        for (int y=2; y<=N-K; y++){
            for (int k=1; k<x; k++){
                dp[x][y] = min(dp[x][y], dp[k][y-1]+max(0LL, height[x]-height[k]));
            }
        }
    }
    ll ans = LONG_LONG_MAX;
    for (int i=1; i<=N; i++){
        ans = min(ans, dp[i][N-K]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem141a(s))
}

fun problem141a(s: String): String {
    return when (s) {
        "Sunny" -> "Cloudy"
        "Cloudy" -> "Rainy"
        "Rainy" -> "Sunny"
        else -> ""
    }
}

Measured memory_bytes: 31516
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int ans = inf;
	rep(i, n) cin >> a[i];
	rep2(i,-101,102){
		int temp = 0;
		rep(j, n)
		{
			temp += (i - a[j]) * (i - a[j]);
		}
		ans = min(ans, temp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
n,k,q = (int(x) for x in input().split())
a = []
p = []

for i in range(q):
    a.append(int(input()))

for i in range(n):
    p.append(0)

for i in range(q):
    p[a[i]-1] = p[a[i]-1] + 1

for i in range(n):
    if p[i] > q - k:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8644
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
    for j in range(i+1, n-1):
        k = 2*j - i
        if k < n:
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1
print(ans)


Measured memory_bytes: 9056
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  
  a = 0
  s = A[0]
  cur = 0
  right = 1
  for left in range(N):
    while right < N and s & A[right] == 0:
      s += A[right]
      right += 1
    cur += right - left
    s -= A[left]

  print(cur)


if __name__ == '__main__':
  main()

Measured memory_bytes: 24372
/*
 * Author: madlogic
 * It's better to do something than nothing
*/
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
// #define int long long
const int INF = 1000000000;
const int MOD = 1000000007;
const double PI = 2*acos(0.0);
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,k;
	cin>>n>>k;
	int h[n];
	int res = 0;
	for(int i=0;i<n;i++)
		cin>>h[i],res+=(h[i]>=k);
	cout<<res<<endl;
	return 0;	
}

Measured memory_bytes: 640
H,W = map(int, input().split())

H_output = H+2
W_output = W+2

S = []
for _ in range(H):
    s = list(input())
    S.append(s)
count = 0

for i in range(H_output):
    if i==0 or i==H+1:
        row = ["#"]*(W+2)
        print(*row,sep="")
        continue
    else:
        row_left = ["#"]*1
        row_right = ["#"]*1
        row = row_left + S[count] + row_right
        print(*row,sep="")
        count = count + 1

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

int main(){
    int n,l;
    cin >> n >> l;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    sort(all(s));
    rep(i,n)cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define PB push_back
#define INF 2000000000
#define X first
#define Y second
using namespace std;
const LL mod = 998244353;
const LL MAX = 600005;
string s;
LL can[4005][4005];
LL dp[4005][4005];
LL add(LL a , LL b)
{
	return a + b >= mod ? a + b - mod : a + b;
}

int main()
{
	//freopen("input.txt" , "r" , stdin);
	cin >> s;
	LL n = s.size();

	LL cntBlue = 0 , cntRed = 0;
	//How about last?
	for(LL hid = 0; hid <= 2 * n; hid++)
	{
		for(LL blue = 0; blue <= hid; blue++)
		{
			LL red = hid - blue;
			can[blue][red] = blue <= cntBlue && red <= cntRed &&  (!blue && !red || blue && can[blue - 1][red] || red && can[blue][red - 1]);
		}
		if(hid < n)
		{
			if(s[hid] == '0')
				cntBlue += 2;
			if(s[hid] == '1')
				cntBlue++ , cntRed++;
			if(s[hid] == '2')
				cntRed += 2;
		}
	}
	
	dp[0][0] = 1;
	for(LL cnt = 0; cnt < 2 * n; cnt++)
	{
		for(LL blue = 0; blue <= cnt; blue++)
		{	
			LL red = cnt - blue;
			if(can[blue + 1][red])
				dp[blue + 1][red] = add(dp[blue + 1][red] , dp[blue][red]);
			if(can[blue][red + 1])
				dp[blue][red + 1] = add(dp[blue][red + 1] , dp[blue][red]);
		}
	}
	LL ans = 0;
	for(LL i = 0; i <= 2 * n; i++)
		ans = add(ans , dp[2 * n - i][i]);

	cout << ans;
}

Measured memory_bytes: 248320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int p,q,r; cin >> p >> q >> r;
	cout<<min({p+q,r+q,p+r})<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N, K, Q, tmp;
    scanf("%d%d%d", &N, &K, &Q);

    vector <int> A(N, 0);
    for(int i = 0; i < Q; i++){
        scanf("%d", &tmp);
        A[tmp -1]++;
    }

    for(int i = 0; i < N; i++){
        if(K - (Q - A[i]) > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAX 3004
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(a,b,c) for(int a=b;a<c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
string s,t,ans="";
int dp[MAX][MAX],n,m;
int lscacc()
{
    forn(i,0,n + 1)
        forn(j,0,m + 1)
        {
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else 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]);
        }
    return dp[n][m];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    n = (int)s.size();
    m = (int)t.size();
    int i = n, j = m;
    lscacc();
    while(dp[i][j] != 0)
    {
        if(s[i - 1] == t[j - 1])
        {
            ans = s[i - 1] + ans;
            i--;
            j--;
        }
        else if(dp[i - 1][j] >= dp[i][j - 1])
            i--;
        else
            j--;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 35456
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int mod=100000;
int m,n;
char str[25][25];
//メモリの容量上直前の2マスのみ保存
/* 1~x-1番目のbitは, その場所を基準として, JOが続くか否かを表す.
x番目のbitは, そこにJが来るか来ないかを表す. (JOが作れるか作れないか知るために必要) */
int dp[2][1<<20][3];
int ans=0;
char joi[4]="JOI";

//＼bitDPできない勢／
int main(void){
	//入力
    scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",str[i]);
	}
	//以降JOIができるパターンを数える
	//さいしょ
	dp[0][0][0]=1;
	//使いまわすための変数
	int cur=0,next=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			//初期化
			memset(dp[next],0,sizeof(dp[next]));
			for(int bit=0;bit< (1<<m);bit++){
				for(int p=0;p<2;p++){
					if(dp[cur][bit][p]){
						for(int k=0;k<3;k++){
							//条件に全く当てはまらないのは無視
							if(str[i][j]!='?' && str[i][j]!=joi[k])continue;
							if((bit & 1 << j) && k==2)continue;
							//nbit= 現在のビット AND 1<<jの反転
							//np= kが0であれば1、そうでなければ0
							int nbit = bit & ~(1<<j),np=k==0;
							if(p && k == 1)nbit |= 1<<(j-1);
							dp[next][nbit][np]+=dp[cur][bit][p];
							//modで割る
							if(dp[next][nbit][np]>=mod)dp[next][nbit][np]-=mod;
						}
					}
				}
			}
			//メモリを使い回すためにスワップ
			swap(cur,next);
		}
		for(int bit=0;bit< (1<<m);bit++){
			//条件を満たしたものを足す
			dp[cur][bit][0]+=dp[cur][bit][1];
			//modで割る
			if(dp[cur][bit][0]>=mod)dp[cur][bit][0]-=mod;
			dp[cur][bit][1]=0;
		}
	}
	int ans=1;
	//パターンが何通りあるか数える(?1つにつき×3、modで割る)
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(str[i][j]=='?')ans=(ans*3)%mod;
		}
	}
	//全パターンからJOIができるパターンを引く
	for(int i=0;i< (1<<m);i++)ans=(ans+mod-dp[cur][i][0])%mod;
	cout << ans << endl;
    return 0;
}

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

using namespace std;

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

    int ans = 0;
    while (n--) {
        int h;
        cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

struct zahyou{
    double x, y;
};

void print_zahyou(zahyou z){
    printf("%.8lf %.8lf\n",z.x,z.y);
}

void koch(int d,zahyou p1,zahyou p2){
    zahyou s, u, t;
    if(d==0) return;
    s.x=(2*p1.x+1*p2.x)/3;
    s.y=(2*p1.y+1*p2.y)/3;
    t.x=(1*p1.x+2*p2.x)/3;
    t.y=(1*p1.y+2*p2.y)/3;
    u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
    u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
    koch(d-1,p1,s);
    print_zahyou(s);
    koch(d-1,s,u);
    print_zahyou(u);
    koch(d-1,u,t);
    print_zahyou(t);
    koch(d-1,t,p2);
}

int main(void){
    int n;
    zahyou p1,p2;
    p1.x=0.0;p1.y=0.0;
    p2.x=100.0;p2.y=0.0;
    cin >> n;
    printf("0.00000000 0.00000000\n");
    koch(n,p1,p2);
    print_zahyou(p2);
    return 0;
}



Measured memory_bytes: 3196
a = int(input())
b = int(input())
c = int(input())
x = int(input())

counter = 0

def coinNumToSum(a, b, c):
  return 500 * a + 100 * b + 50 * c

for aindex in range(a+1):
  for bindex in range(b+1):
    for cindex in range(c+1):
      if coinNumToSum(aindex, bindex, cindex) == x:
        counter += 1

print(counter)

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    ll ans = 0;
    ll sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
        if(i % 2 == 0 and sum <= 0){
            ans += (1 - sum);
            sum = 1;
        }else if(i % 2 == 1 and sum >= 0){
            ans += sum + 1;
            sum = -1;
        }
    }
    sum = 0;
    ll ans2 = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
        if(i % 2 == 0 and sum >= 0){
            ans2 += 1 + sum;
            sum = -1;
        }else if(i % 2 == 1 and sum <= 0){
            ans2 += (1 - sum);
            sum = 1;
        }
    }
    cout << min(ans, ans2) << endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int h = inint(), w = inint();
		out.println(h*w - h - w + 1);
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}
	
	public int inint() {
		return in.nextInt();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}
	
	public char[] incharar() {
		return in.next().toCharArray();
	}
	
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'o') {
			ans++;
		}
	}

	if (15 - s.length() + ans >= 8) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main() {
  string s; cin >> s;
  ll k; cin >> k;

  char ans = '1';
  rep(i,s.size()){
    if(s[i] != '1'){
      ans = s[i];
      break;
    }
    else if(i == k-1) break;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n, m;
int a[maxn + 10][maxn + 10], b[maxn + 10][maxn + 10];
bool c[maxn + 10][maxn + 10];
int lk[maxn + 10], d[maxn + 10];
bool vis[maxn + 10];
bool ban[maxn + 10][maxn + 10];

bool cmp(int x, int y) {
	return (x - 1) / m + 1 < (y - 1) / m + 1;
}

bool dfs(int p) {
	for (int i = 1; i <= n; ++i)
		if (c[p][i] && !vis[i]) {
			vis[i] = 1;
			if (!lk[i] || dfs(lk[i])) {
				lk[i] = p; return 1;
			}
		}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
	for (int i = 1; i <= m; ++i) {
		memset(c, 0, sizeof c);
		memset(lk, 0, sizeof lk);
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= m; ++k)
				if (!ban[j][k])
					c[j][(a[j][k] - 1) / m + 1] = 1;
		for (int j = 1; j <= n; ++j) {
			memset(vis, 0, sizeof vis);
			assert(dfs(j));
		}				
		for (int j = 1; j <= n; ++j) {
			int pos = lk[j];
			for (int k = 1; k <= m; ++k)
				if (!ban[pos][k] && (a[pos][k] - 1) / m + 1 == j) {
					ban[pos][k] = 1;
					b[pos][i] = a[pos][k];
					break;
				}
		}
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			printf("%d%c", b[i][j], " \n"[j == m]);
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j)
			d[j] = b[j][i];
		sort(d + 1, d + n + 1, cmp);
		for (int j = 1; j <= n; ++j)
			b[j][i] = d[j];
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			printf("%d%c", b[i][j], " \n"[j == m]);
}


Measured memory_bytes: 512
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, L = get_ints

wa = L * N + ((N * (N-1)) /2)

sa = 10**9
[*1..N].each do |i|
  x = L + i - 1
  sa = x if x.abs < sa.abs
end

puts wa - sa


Measured memory_bytes: 14508
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,c=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<=n-3;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')c++;
    }
    cout<<c;
    return 0;
}


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

using std :: map;

static const int maxm = 1e6 + 10;

map<int,int> cnt;

int A[maxm];
int n;

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%d",&A[i]),cnt[A[i]]++;
	
	std :: sort(A + 1,A + n + 1);

	long long x = 0,y = 0;
	
	for(int i = n;i;i--){
		if(x && y) break;
		if(cnt[A[i]] >= 2 && !x) x = A[i],cnt[A[i]] -= 2;
		else if(cnt[A[i]] >= 2 && !y) y = A[i],cnt[A[i]] -= 2;
	}

	printf("%lld\n",1LL * x * y);

	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	string s,t;
	cin >> s >> t;
	bool bb=0;
	char a;
	SREP(i,s){
		if(s==t) bb=1;
		a=s[s.size()-1];
		REP(i,s.size()-1){
			s[s.size()-i-1]=s[s.size()-i-2];
		}
		s[0]=a;
	}
	cout << (bb ? "Yes" : "No") << endl;
/////////////////////////////////////////////
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,K;
  cin >> N >> K;
  vector<int> L(K),R(K);
  for(int i=0; i<K; i++){
    cin >> L[i] >> R[i];
    R[i]++;
  }
  vector<ll> dp(3*N,0);
  dp[1] = 1;
  vector<ll> DP(3*N,0);
  for(int i=1; i<=N; i++){
    dp[i] += DP[i];
    dp[i] %= mod;
    for(int j=0; j<K; j++){
      DP[i+L[j]] += dp[i];
      DP[i+L[j]] %= mod;
      DP[i+R[j]] -= dp[i];
      DP[i+R[j]] += mod;
      DP[i+R[j]] %= mod;
    }
    DP[i+1] += DP[i];
    DP[i+1] %= mod;
  }  
  // for(int i=0; i<=N; i++){
  //   cout << DP[i] << " \n"[i==N];
  // }
  cout << dp[N] << "\n";
  return 0;
}

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

int main() {
	long long N;
    cin >> N;

    long long i = 1;
    while (i * i <= N) {
      i++;
    }
    i--;
    
  	long long j;
    for (; ; i--) {
      	if (N % i == 0) {
          j = N / i;
          break;
        }
    }
  
    cout << i + j - 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[110][110],h[110],w[110];
int main(){
  int m,n;
  char c;
  memset(a,0,sizeof(a));
  memset(h,0,sizeof(h));
  memset(w,0,sizeof(w));
  cin>>m>>n;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++){
      cin>>c;
      if(c=='\n')cin>>c;
      if(c=='#')h[i]=1,w[j]=1,a[i][j]=1;
      else a[i][j]=0;
    }
  for(int i=0;i<m;i++){
    if(!h[i])continue;
    for(int j=0;j<n;j++){
      if(!w[j])continue;
      if(a[i][j])cout<<'#';
      else cout<<'.';
    }
    cout<<'\n';
  }
  return 0;
}

Measured memory_bytes: 256
def prepare(m, mod=10 ** 9 + 7):
	fac = [1] * (m + 1)
	inv = [1] * (m + 1)
	for i in range(1, m + 1):
		fac[i] = fac[i - 1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m - 1, -1, -1):
		inv[i] = inv[i + 1] * (i + 1) % mod
	return fac, inv

n, k = map(int, input().split())
mod = 10 ** 9 + 7
fac, inv = prepare(n)

def cmb(n, r):
	assert n >= r >= 0
	return fac[n] * inv[n - r] * inv[r] % mod

ans = 0
for i in range(min(n, k + 1)):
	ans += cmb(n, i) * cmb(n - 1, i)
	ans %= mod
print(ans % mod)

Measured memory_bytes: 18804
// inputに入力データ全体が入る
function Main(input) {
  lines = input.split("\n");
  numbers = lines[1].split(" ");
  iterations = numbers.length;
  count = 0;
  
  for(i=0; i<iterations-2; i++){
    var max = Math.max(numbers[0], numbers[1], numbers[2]);
    var min = Math.min(numbers[0], numbers[1], numbers[2]);
    if(numbers[1] != max && numbers[1] != min){
      count += 1;
    }
    
    numbers.splice(0,1);
  }
  
  console.log(count);

}
  
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include<iostream>
using namespace std;
int main(){
	int a;
    int sum=0;
    cin >> a;
    int b=a;
    while(a)
    {
        sum = sum + a%10;
        a = a/10;
    }
    if (b%sum==0){
        printf("Yes");
    }else{ 
        printf("No");
}
}

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

	int x;
	int y;
	int [][] block;

	class C {
		int x1;
		int y1;
		int x2;
		int y2;
		int count;
		public C(int x1, int y1, int x2, int y2, int count) {
			super();
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
			this.count = count;
		}
	}

	private boolean isBlock(int x1, int y1){
		if(block[y1][x1] == 1)
			return true;
		else
			return false;
	}

	private boolean isOut(int x1, int y1){
		if(x1 <= 0 || x1 > x || y1 <= 0 || y1 > y )
			return true;
		return false;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			x = sc.nextInt();
			y = sc.nextInt();
			if(x == 0 && y == 0){
				break;
			}
			LinkedList<C>open  = new LinkedList<C>();
			boolean[][][][] close = new boolean [x+1][y+1][x+1][y+1];
			int [] xdir = {0,1,0,-1};
			int [] ydir = {1,0,-1,0};
			int tx = sc.nextInt();
			int ty  = sc.nextInt();
			int kx = sc.nextInt();
			int ky  = sc.nextInt();
			block = new int [y+1][x+1];
			for(int i=1; i <= y; i++){
				for(int j=1; j <= x; j++){
					block[i][j] = sc.nextInt();
				}
			}

			//set a first
			open.add(new C(tx, ty, kx, ky,0));

			close[tx][ty][kx][ky] = true;
			boolean flg = false;

			while(!open.isEmpty()){
				C temp = open.getFirst();
				open.removeFirst();
				int x1 = temp.x1;
				int y1 = temp.y1;
				int x2 = temp.x2;
				int y2 = temp.y2;
				int c = temp.count;
				//goal
				if(x1 == x2 && y1 == y2){
					flg = true;
					System.out.println(c);
					break;
				}
				for(int i=0; i < 4; i++){
					int temp1 = x1 + xdir[i];
					int temp2 = y1 + ydir[i];
					int temp3 = x2 + xdir[i] * -1;
					int temp4 = y2 + ydir[i] * -1;
					if(isOut(temp1, temp2) || isBlock(temp1, temp2)){
						temp1 = x1;
						temp2 = y1;
					}
					if(isOut(temp3, temp4) || isBlock(temp3, temp4)){
						temp3 = x2;
						temp4 = y2;
					}
					if( ! close[temp1][temp2][temp3][temp4]){
						open.addLast(new C(temp1,temp2,temp3,temp4,c + 1));
						close[temp1][temp2][temp3][temp4] = true;
					}
				}
			}
			if(!flg) System.out.println("NA");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 28000
n,C=map(int,input().split())
dp=[[0 for i in range(100002)] for j in range(31)]
for i in range(n):
  s,t,c=map(int,input().split())
  t+=1
  dp[c][s]+=1
  dp[c][t]-=1
nm=[0 for i in range(100002)]
for i in range(31):
  s=1
  for j in range(1,100002):
    dp[i][j]+=dp[i][j-1]
    if dp[i][j]==0 and dp[i][j-1]==1:
      nm[s]+=1
      nm[j]-=1
    elif dp[i][j]==1 and dp[i][j-1]==0:
      s=j
for i in range(1,100002):
  nm[i]+=nm[i-1]
print(max(nm))

Measured memory_bytes: 118728
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=2e5+10; 
int h[N];
map<int,int>mp;
signed main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		int j=i-h[i];
		sum += mp[j];
		
		mp[h[i]+i]++;
	}
	cout << sum<<endl;
	return 0;
}


Measured memory_bytes: 27756
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String line = r.readLine();
        while (line != null) {
            handleLine(line);
            line = r.readLine();
        }
    }
    
    public static void handleLine(String line) {
        int value = Integer.parseInt(line);
        System.out.println("" + (value * value * value));
    }
}

Measured memory_bytes: 24280
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

	vector<bool> ac(n, true);
	vector<int> wa(n);
	int t;
	string str;
	int ans_ac = 0;
	int ans_wa = 0;
	for (int i = 0; i < m; i++) {
		cin >> t >> str;

		if (str == "AC" && ac[t - 1]) {
			ac[t - 1] = false;
			ans_ac++;
			ans_wa += wa[t - 1];
		}
		else {
			wa[t - 1]++;
		}
	}
	
	cout << ans_ac << " " << ans_wa << endl;

	return 0;
}

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

int main()
{
    int n, y;
    cin >> n >> y;
    for (int a = 0; a <= n; a++) {
        for (int b = 0; b <= n; b++) {
            int c = n - a - b;
            if (c >= 0 && 10000*a + 5000*b + 1000*c == y) {
                cout << a << " " << b << " " << c << endl;
                return 0;   
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

#define MOD 1000000007

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

    int N; cin >>N;
    vector<int> A(N+1);
    vector<int> pos(N, -1);
    int l, r;
    rep(i, N+1) {
        cin >> A[i];
        A[i]--;
        if (pos[A[i]] == -1) {
            pos[A[i]] = i;
        } else {
            l = pos[A[i]];
            r = i;
        }
    }

    vector<int> fact(N+1+1);
    vector<int> finv(fact.size());
    vector<int> inv(fact.size());
    
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[0] = 0; inv[1] = 1;
    for (int i = 2; i < fact.size(); i++) {
        fact[i] = (ll)fact[i-1] * i % MOD;
        inv[i] = MOD - (ll)inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
    }

    auto C = [&](int n, int r) { return (ll)fact[n] * finv[n-r] % MOD * finv[r] % MOD; };

    cout << N+1-1 << endl;
    for (int k = 2; k <= N+1; k++) {
        int a = C(N+1, k);
        int b = l + N+1-(r+1) >= k - 1 ? C(l + N+1-(r+1), k-1) : 0;
        int s = ((ll)a - b) % MOD;
        while (s < 0) s += MOD;
        cout << s << endl;
    }
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <math.h>
int main (){
	
	int a,b;
	scanf ("%d %d",&a,&b);
	int k=b;
	int i=0;
	while (k>0){
		k=k/10;
		i++;
	}
	a=a*(pow(10,i));
	k=a+b;
	if (floor(sqrt(k))==ceil(sqrt(k))){
		printf ("Yes");
	}
	else {
		printf ("No");
	}
	
	return 0;
}

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

int main(){
  string s; cin>>s;
  int N = s.length();
  vector<int> v;
  for(auto c:s){
    v.push_back(c-'0');
  }
  sort(v.begin(),v.end());
  auto it = lower_bound(v.begin(), v.end(), 1);
  int nz = it-v.begin();
  int no = v.end()-it;
  cout<<N-abs(nz-no)<<endl;
  return 0;
}

Measured memory_bytes: 1020