akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define sc(t) scanf("%c",&t)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define clr(x) memset(x,0,sizeof(x))
#define rep(i,begin,end) for(__typeof(end) i=begin-(begin>end);i!=end-(begin>end);i+=1-2*(begin>end))
#define MOD 1000000007
#define MAX 505
#define EPS 1e-9
using namespace std;

int main()
{
	fio;
	map<char,int> m;
	string s;
	cin>>s;
	for(auto it:s) m[it]++;
	int flag=0;
	for(auto it:m) flag+=it.second%2;
	cout<<(flag?"No":"Yes")<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int a, b;
   char op;
   while(1){
       scanf("%d %c %d", &a, &op, &b);
       if(op=='?'){
           break;
       }else if(op=='+'){
           printf("%d\n", a+b);
       }else if(op=='-'){
           printf("%d\n", a-b);
       }else if(op=='*'){
           printf("%d\n", a*b);
       }else if(op=='/'){
           printf("%d\n", a/b);
       }
   }
   return 0;
}


Measured memory_bytes: 2140
n=int(input())
L=[]
for i in range(1,n+1):
      a,b=input().split()
      L.append((i,a,int(b)))
      
L.sort(key=lambda x:x[2],reverse=True)
L.sort(key=lambda x:x[1])

for i in range(n):
      print(L[i][0])

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int H,W;
    scanf("%d %d",&H,&W);
    int dist[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)scanf("%d",&dist[i][j]);
    for(int k=0;k<10;k++)for(int i=0;i<10;i++)for(int j=0;j<10;j++){
        if(dist[i][j]>dist[i][k]+dist[k][j])dist[i][j]=dist[i][k]+dist[k][j];
    }
    int ans=0;
    for(int i=0;i<H*W;i++){
        int kari;
        scanf("%d",&kari);
        if(kari!=-1){ans+=dist[kari][1];}
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
 
typedef pair <int, int> pii;
typedef long long ll;
 
const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 101;
const int MAXW = 1e5 + 1;
 
int n, c;
int w[MAXN], v[MAXN];
ll dp[MAXN][MAXW];
 
int main(){
 
    cin >> n >> c;
    for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];
 
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= c; j++){
            if (w[i] > j) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
 
    cout << dp[n][c];
 
    return 0;
 
}

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

int gcd(int x,int y) {
	int ans;
	
	ans = x % y;
	if (ans == 0) {
		return y;
	}
	
	return gcd(y, ans);

	
}

int main() {
	int x, y;
	int ans;
	int tmp;
	cin >> x >> y;
	tmp = max(x, y);
	if (tmp == y) {
		y = x;
		x = tmp;
	}
	ans=gcd(x, y);

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3096
#include<iostream>

using namespace std;

int main(){

	int n;

	long long a;

	long long minvalue = 1000000;

	long long maxvalue = -1000000;

	long long sum = 0;

	cin >> n;

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

		cin >> a;

		if ( a < minvalue ) minvalue = a;

		if ( a > maxvalue ) maxvalue = a;

		sum += a;

	}

	cout << minvalue << " " << maxvalue << " " << sum << endl;

	return 0;

}

Measured memory_bytes: 1168
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)
	m := getNextInt64(scanner)

	if n == 1 && m == 1 {
		fmt.Println(1)
		return
	}

	if n == 1 {
		fmt.Println(m - 2)
		return
	}
	if m == 1 {
		fmt.Println(n - 2)
		return
	}

	fmt.Println((n - 2) * (m - 2))
	writer.Flush()
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define FL "a"
using namespace std;
typedef long long ll;
typedef long double dd;
const int N=2e5+10;
const int mod=1e9+7;
inline ll read(){
  ll d=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')d=d*10+ch-48,ch=getchar();
  return d*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,q;char s[N],o[N][5];
int main()
{
  n=read();q=read();
  scanf("%s",s+1);
  for(int i=1,c;i<=q;i++){
    c=0;while(c<'A'||c>'Z')c=getchar();o[i][1]=c;
    c=0;while(c<'A'||c>'Z')c=getchar();o[i][2]=c;
  }
  
  int l=1,r=n,mid,p,p1=0,flg;
  while(l<=r){
    mid=(l+r)>>1;p=mid;flg=0;
    for(int i=1;i<=q;i++)
      if(o[i][1]==s[p]){
	o[i][2]=='L'?p--:p++;
	if(p==0){flg=1;break;}
	else if(p==n+1)break;
      }
    flg?p1=mid,l=mid+1:r=mid-1;
  }
  int p2=n+1;l=p1+1;r=n;
  while(l<=r){
    mid=(l+r)>>1;p=mid;flg=0;//printf("%d:\n",p);
    for(int i=1;i<=q;i++)
      if(o[i][1]==s[p]){
	o[i][2]=='L'?p--:p++;
	if(p==n+1){flg=1;break;}
	else if(p==0)break;
      }
    flg?p2=mid,r=mid-1:l=mid+1;
  }
  p1=max(0,p1);p2=min(n+1,p2);
  //printf("%d,%d\n",p1,p2);
  printf("%d\n",n-(p1)-(n-p2+1));
  return 0;
}


Measured memory_bytes: 1408
"""Binary Trees."""

class Node:
    def __init__(self, num, leftChild, rightChild):
        self.id = num
        self.parent = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = 'leaf'
        self.leftChild = leftChild
        self.rightChild = rightChild
        
    def show_info(self):
        print('node {}:'.format(self.id), 'parent = {},'.format(self.parent),
              'sibling = {},'.format(self.sibling),
              'degree = {},'.format(self.degree),
              'depth = {},'.format(self.depth),
              'height = {},'.format(self.height),
              '{}'.format(self.type))


def set_attributes(n_i, parent, sibling, depth):
    if n_i == -1:
        return -1
    node = T[n_i]
    lc = node.leftChild
    rc = node.rightChild
    node.parent = parent
    node.sibling = sibling
    node.depth = depth
    node.degree = (node.leftChild != -1) + (node.rightChild != -1)
    if lc != -1 or rc != -1:
        node.type = 'internal node'
    node.height = max(set_attributes(lc, n_i, rc, depth + 1),
                      set_attributes(rc, n_i, lc, depth + 1)) + 1
    return node.height



import sys

n = int(sys.stdin.readline())

T = [None] * n

rt_n = int(n * (n - 1) / 2)

for x in sys.stdin.readlines():
    num, leftChild, rightChild = list(map(int, x.split()))
    node = Node(num, leftChild, rightChild)
    T[num] = node
    rt_n -= (max(0, leftChild) + max(0, rightChild))

set_attributes(rt_n, -1, -1, 0)

T[rt_n].type = 'root'

for n in T:
    n.show_info()

Measured memory_bytes: 7848
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)
	{
		char a;
		cin>>a;
		if(a=='a'||a=='e'||a=='o'||a=='i'||a=='u')
		cout<<"vowel";
		else
		cout<<"consonant";

	}
	return 0;
}


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

long long n,a,b;
long long ans[300011];
long long c[300011];
long long s[300011];
int main()
{
    long long i,j;
    
    cin>>n>>a>>b;
    
    if(a+b>n+1)
    {
        cout<<-1<<endl;
        return 0;
    }
    
    if(a*b<n)
    {
        cout<<-1<<endl;
        return 0;
    }
    
    long long nn=n;
    n-=b;
    c[1]=b;
    for(i=2;i<=a;i++)
    {
        c[i]=1;
        n--;
    }
    
    i=2;
    while(n>0)
    {
        //cout<<n<<' '<<i<<' '<<c[i]<<endl;
        if(n>=b-c[i])
        {
            n-=(b-c[i]);
            c[i]=b;
        }
        else
        {
            c[i]+=n;
            n=0;
        }
        i++;
    }
    
    /*
    for(i=1;i<=a;i++)
    {
        cout<<c[i]<<' ';
    }
    cout<<"!!!"<<endl;
    */
    s[1]=1;
    for(i=2;i<=a;i++)
    {
        s[i]=s[i-1]+c[i-1];
    }
    
    j=1;
    for(i=1;i<=nn;i++)
    {
        if(c[j]==0)
        {
            j=1;
            i--;
            continue;
        }
        
        ans[i]=s[j]+c[j]-1;
        c[j]--;
        j++;
    }
    
    for(i=1;i<nn;i++)
    {
        cout<<ans[i]<<' ';
    }
    cout<<ans[i]<<endl;

    
    return 0;
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>                                                      
using namespace std;
int main(){
  int N;
  cin >> N;
  int count=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if((4*i+7*j)==N)
        count++;
    }
  }
  if(count==0){
    cout << "No" << endl;
  }
  else
    cout << "Yes" << endl;
}

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

struct UnionFind{
	vector<long> par;
	vector<long> siz;

	UnionFind(long N) : par(N), siz(N) {
		for(long i=0;i<N;++i){
			 par[i] = i;
			 siz[i] = 1;
		}
	}

	long root(long x){
		if(par[x] == x) return x;
		else root(par[x]);
	}

	void unite(long x, long y){
		long rx = root(x);
		long ry = root(y);
		if(rx == ry) return;
		else {
			if(siz[rx]<siz[ry]){
				siz[ry] += siz[rx];
				par[rx] = ry;
			}
			else {
				siz[rx] += siz[ry];
				par[ry] = rx;
			}
		}
	}

	bool same(long x, long y){
		long rx = root(x);
		long ry = root(y);
		return rx == ry;
	}

	long size(long x){
		return siz[root(x)];
	}
};

int main() {
	long N, M;
	cin>>N>>M;
	long A[M], B[M];
	for(long i=0;i<M;++i){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
	}

	UnionFind tree(N);

	long ans[M];
	ans[M-1] = N*(N-1)/2;

	for(long i=M-1;i>0;--i){
		if(!tree.same(A[i], B[i])){
			ans[i-1] = ans[i] - tree.size(A[i])*tree.size(B[i]);
			tree.unite(A[i], B[i]);
		}
		else {
			ans[i-1] = ans[i];
		}
	}
	for(long i=0;i<M;++i){
		cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 5248
n,m=gets.chomp.split(" ").map(&:to_i)
ys={}
lines=[]
ls=[]
while l=gets
  next if l.chomp == ""
  p,y=l.chomp.split(" ").map(&:to_i)
  lines<<{y: y, p: p.to_s}
  ys[p] ||= []
  ys[p] << y
end
ys.each_pair{|_,v|v.sort! if v.length > 1 }
lines.each do |x|
  puts "#{x[:p].rjust(6, "0")}#{ys[x[:p].to_i].bsearch_index {|yy| x[:y]<=yy }.next.to_s.rjust(6, "0")}"
end

Measured memory_bytes: 54780
NM = [int(i) for i in input().split()]
check = [0] * NM[1]
index = 0
N = NM[0]
while(NM[0] > 0):
    KA = [int(i) for i in input().split()]
    A = KA[1:]
    for i in A:
        check[i - 1] += 1
    NM[0] -= 1
count = 0
for i in check:
    if i == N:
        count += 1

print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int count = 0;
    int remain = 15 - S.length();
    String ans;

    for(int i = 0; i < S.length(); i++) {
    	char c = S.charAt(i);
    	if(c == 'o') {
    		count++;
    	}
    }

    count += remain;

    if(count >= 8) {
    	ans = "YES";
    } else {
    	ans = "NO";
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 22356
n=int(input())
A=list(map(int,input().split()))
zo=0 ; mi=0 ;ans=1
for i in range(n-1):
    #print(zo,mi,i)
    if zo==mi==0:
        if A[i]==A[i+1]:
            continue
        elif A[i]>A[i+1]:
            mi=1; continue
        else:
            zo=1;continue
    if zo:
        if A[i+1]<A[i]:
            zo=0; ans+=1
    if mi and A[i]<A[i+1]:
        mi=0 ; ans+=1
print(ans)

Measured memory_bytes: 84660
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll N, K;
vector<ll> a;

bool nn(ll x) {

	if (a[x] > K) { return false; }

	vector<bool> dp(K+1, 0);
	dp[0] = 1;

	repn(i, N) {
		if (i == x) { continue; }

		vector<ll> v;
		rep(j, K) {
			if (j >= a[i] && dp[j - a[i]] == 1) { v.push_back(j); }
		}
		rep(k, v.size()) { dp[v[k]] = 1; }
	}


	rep(j, a[x]) {
		if (dp[K - a[x] + j] == 1) { return false; }
	}

	return true;
}



int main() {

	cin >> N >> K;
	a.resize(N + 1);

	repn(i, N) cin >> a[i];
	sort(++a.begin(), a.end());

	ll l = 0;
	ll r = N + 1;

	while (r - l > 1) {
		ll m = (r + l) / 2;

	
		if (nn(m)) { l = m; }
		else { r = m; }
	}
	
	cout << l;
	system("PAUSE");
}


Measured memory_bytes: 632
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
a.sort()

ai = a.max()

v, aj = 0, 0
for i in a[:-1]:
    tmp = i * (ai - i)
    if v < tmp:
        v = tmp
        aj = i
# print(v, aj)
print(ai)
print(aj)


Measured memory_bytes: 32516
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
using namespace std;
int main()
{
	long lnN = 0;
	long lnH = 0;
	long lnW = 0;
	cin >> lnN >> lnH >> lnW;

	int nCnt = 0;
	for (int i = 0; i < lnN; i++)
	{
		long lnA, lnB;
		cin >> lnA >> lnB;
		if (lnH <= lnA && lnW <= lnB)
			nCnt++;

	}
	cout << nCnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define for_(i,a,b) for(int i=(a);i<(b);++i)
template< typename T > using Vec = vector< T >;
typedef long long lint;
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
 
struct Edge {
	int v;
	lint d;
	bool operator > (const Edge& e) const { return d > e.d; }
};
 
int N, M, S, T, U[200005], V[200005];
lint D[200005];
Vec< Vec< Edge > > edge;
 
lint dst[2][100005];
lint numpath[2][100010];
const lint MOD = (lint)1e9 + 7;
 
void calcDist(int piv, int start) {
	priority_queue< Edge, Vec< Edge >, greater< Edge > > que;
	que.push(Edge{start, 0});
	dst[piv][start] = 0;
	numpath[piv][start] = 1;
	while (!que.empty()) {
		Edge e = que.top(); que.pop();
		//if (dst[piv][e.v] < e.d) continue;
		for (const Edge& ei : edge[e.v]) {
			if (dst[piv][ei.v] == -1 || dst[piv][ei.v] > e.d + ei.d) {
				dst[piv][ei.v] = e.d + ei.d;
				numpath[piv][ei.v] = numpath[piv][e.v];
				que.push(Edge{ei.v, dst[piv][ei.v]});
			} else if (dst[piv][ei.v] == e.d + ei.d) {
				modAdd(numpath[piv][ei.v], numpath[piv][e.v], MOD);
			}
		}
	}
}
 
void solve() {
	memset(dst, -1, sizeof(dst));
	calcDist(0, S);
	calcDist(1, T);
  
  assert(numpath[0][T] == numpath[1][S]);
	
	lint collision = 0;	
	
	for_(v,0,N) {
		if (dst[0][v] == dst[1][v] && dst[0][v] + dst[1][v] == dst[0][T]) {
			lint num = (numpath[0][v] * numpath[1][v]) % MOD;
			modAdd(collision, num * num, MOD);
		}
	}
	
	double thr = (double)dst[0][T] / 2.;
	for_(i,0,M) {
		int u = U[i], v = V[i], d = D[i];
		if (abs(dst[0][v] - dst[0][u]) == d) {
			if (dst[0][v] + d == dst[0][u]) swap(u, v);
			if (dst[0][u] + dst[1][v] + d == dst[0][T] && (double)dst[0][u] < thr && (double)(dst[0][u] + d) > thr) {
				lint num = (numpath[0][u] * numpath[1][v]) % MOD;
				modAdd(collision, num * num, MOD);
			}
		}
	}
	
	cout << ((numpath[0][T] * numpath[1][S] - collision + MOD) % MOD) << endl;
}
 
int main() {
	cin >> N >> M;
	cin >> S >> T;
	--S; --T;
	
	edge.assign(N, Vec< Edge >());
	for_(i,0,M) {
		cin >> U[i] >> V[i] >> D[i];
		--U[i]; --V[i];
		edge[U[i]].push_back(Edge{V[i], D[i]});
		edge[V[i]].push_back(Edge{U[i], D[i]});
	}
	
	solve();
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  long double r; cin>>r;
  long double pi=3.14159265358979323846;
  fix(9);
  co(r*r*pi<<" "<<2*r*pi);
  return 0;
}


Measured memory_bytes: 3276
def knapsack_weight_num():
    """
   　各品物の個数に上限がある場合
    """
    """ dp[weight <= W] = 重さ上限を固定した時の最大価値 """
    dp_min = 0  # 総和価値の最小値
    dp = [dp_min] * (W + 1)

    for item in range(N):
        S = range(W, weight_list[item] - 1, -1)
        for weight in S:
            dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[item])
    return dp[W]

#######################################################################################################
import sys
input = sys.stdin.readline


def max2(x, y):
    """ pythonの組み込み関数 max は2変数に対しては遅い！！ """
    if x > y:
        return x
    else:
        return y

def min2(x, y):
    """ pythonの組み込み関数 min は2変数に対しては遅い！！ """
    if x < y:
        return x
    else:
        return y



N, W = map(int, input().split())                                # N: 品物の種類 W: 重量制限


price_list = []
weight_list = []

for _ in range(N):
    # weight, price, cnt = map(int, input().split())
    price, weight, cnt = map(int, input().split())              # cnt: 各品物の個数の上限
    c = 1
    while c <= cnt:
        price_list.append(price*c)
        weight_list.append(weight*c)
        cnt -= c
        c <<= 1
    if cnt:
        price_list.append(price*cnt)
        weight_list.append(weight*cnt)


N = len(price_list)                                              # 品物の種類が変わってる

print(knapsack_weight_num())


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

int main(){

    int A,B,N,M,H,W;
    int i,j,k;
    int min = 1000000000;
    int max = 0;
//    int a,b,c,d;
    int count=0,count_two=0,v;
    string moji[50];

    char c;

    cin >> c;   
 
    if(c == 'a' ||c == 'i' ||c == 'u' ||c == 'e' ||c == 'o')cout << "vowel" << endl;

    else cout << "consonant" << endl;

    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
R=[0]*(M-1)
L=list(map(int,input().split()))
L=sorted(L)
for i in range(M-1):
  R[i]=abs(L[i+1]-L[i])
c=max(L)-min(L)
R=sorted(R,reverse=True)
print(c-sum(R[:min(N-1,len(R))]))

Measured memory_bytes: 21132
import math
while(True):
    if input() == '0':
        break
    a = list(map(int, input().split()))
    m = sum(a) / len(a)
    b = 0
    for i in a:
        b += (i - m) ** 2.0
    stddev = math.sqrt(b / len(a))
    print(stddev)


Measured memory_bytes: 5700
a,b,c,d=map(int,input().split(' '))
if a>=0:
  if d<=0:
    ans=a*d
  else:
  	x=b
  	y=d
  	ans=b*d
elif a<=0 and b>=0:
  if c>=0:
    x=b
    y=d
    ans=b*d
  elif c<=0 and d>=0:
      ans=max(a*c,b*d)
  else:
    ans=a*c
else:
  if c>=0:
    ans=b*c
  else:
    ans=a*c
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;




int main() {
	int N, A, B;
	cin >> N >> A >> B;
	for (int i = 0;; i++) {
		if (i % 2) {
			if (A != B - 1) {
				B--;
			}
			else {
				cout << "Alice" << endl; 
				return 0;
			}
		}
		else {
			if (B != A + 1) {
				A++;
			}
			else {
				cout << "Borys" << endl;
				return 0;
			}
		}
	}
	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 51;

int N, X;
int ssize[MAX_N];
int psize[MAX_N];

int ans = 0;

void calc(int level, int x)
{
  if(x <= 0) {
    return;
  }
  if(level == 0) {
    ans++;
    return;
  }
  if(x <= ssize[level-1]+1) {
    calc(level-1,x-1);
  } else if(x == ssize[level-1]+2) {
    ans += 1 + psize[level-1];
    return;
  } else {
    ans += 1 + psize[level-1];
    calc(level-1, x-2-ssize[level-1]);
  }
}

signed main()
{
  ssize[0] = psize[0] = 1;
  FOR(n,1,MAX_N) {
    ssize[n] = 3 + 2*ssize[n-1];
    psize[n] = 1 + 2*psize[n-1];
  }
  cin >> N >> X;

  calc(N, X);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
sat = 0

pre = -1
for i in a:
  sat += b[i-1]
  #print(b[i-1])
  if pre + 1 == i:
    sat += c[pre-1]
    #print("c", c[pre-1])
  pre = i
print(sat) 

Measured memory_bytes: 38256
#include<iostream>

using namespace std;
int main()
{
    string s;
    int n;
    cin >> n >> s;
    int sum = 0;
    for (int i = 0, r = s.length(); i < r; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            sum++;
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <stdio.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}

int main(int argc, char **argv) {
    int n = get_uint();
    int G[100][100] = {};
    for(int i = 0; i < n; ++i) {
        int u = get_uint() - 1;
        int k = get_uint();
        for(int j = 0; j < k; ++j) G[u][get_uint() - 1] = 1;
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j) {
            put_uint(G[i][j]);
            putchar_unlocked(j == n - 1 ? '\n' : ' ');
        }
    return 0;
}



Measured memory_bytes: 2044
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		if(n+m >= 10){
			System.out.println("error");
		}else {
			System.out.println(n+m);
		}
	}
}


Measured memory_bytes: 22100
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    string S;cin >> S;
    map<int,long long> M;
    for(int i = 0;i<N;i++){
        int idx = S.at(i)-'0';
        M[idx]++;
    }
    long long ans = 1;
    for(auto V : M){
        ans *= V.second+1;
        ans %= MOD;
    }
    ans -= 1;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}


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

using namespace std;

queue<long long int>q;

void solve(vector<long long int>v[],long long int ind[],long long int dist[]){
     long long int x=q.front();
     q.pop();
     for(auto i=v[x].begin();i!=v[x].end();i++){
        ind[*i]--;
        if(ind[*i]==0){
                dist[*i]=dist[x]+1;
            q.push(*i);}
     }
}

int main()
{
    long long int n,e;
    cin>>n>>e;
    if(e==1){ cout<<1;
    return 0;}
    long long int ind[n+1]={0};
    long long int outd[n+1]={0};
    vector<long long int>v[n+1];
    long long int dist[n+1]={0};
    for(long long int i=0;i<e;i++){
        long long int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        ind[y]++;
        outd[x]++;
    }
    for(long long int i=1;i<=n;i++){
        if(ind[i]==0)
            q.push(i);
    }
    while(!q.empty()){
        solve(v,ind,dist);
    } long long int ans=0;
    for(long long int i=1;i<=n;i++)
        ans=max(ans,dist[i]);
    cout<<ans;
    return 0;
}


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



/*1234みたいな数字があってまず%10することで末尾のけたを取り出す。その後割る10
　することで取り出した部分を除くことができる*/
void seven(int a,int i, vector<int> &kurai){


    if (a > 0 && i < 4)
        
    {
        kurai[i] = a % 10;
        a /= 10;
        
        i++;
        seven(a, i, kurai);   
    }

    return ;

}

int main()
{
    int integer;
    cin >> integer;
    vector<int> kurai(3);
    seven(integer,0,kurai);

    int d = kurai[0];
    int c = kurai[1];
    int b = kurai[2];
    int a = kurai[3];
     


if(a+b+c+d == 7){
    cout << a <<"+"<< b << "+" <<c <<"+" <<d <<"=7" << endl;
}
else if (a + b - c + d == 7) {
    cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
}

else if (a + b + c - d == 7) {
    cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
}
else if (a + b - c - d == 7) {
    cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
}
else if (a - b + c + d == 7) {
    cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
}
else if (a - b - c + d == 7) {
    cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
}
else if (a - b + c - d == 7){
    cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
} 
else if (a - b - c - d == 7){
    cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
}

}




Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double EPS = 1e-10;
const double g = 9.8;	//??????????????? 
const int MAX_N = 55; 

//?????\ 
int N;
double V, X, Y;
double L[MAX_N], R[MAX_N], B[MAX_N], T[MAX_N];

//????????\vy??????????????´???????°????t?§????????????? 
double calc(double vy, double t){
	return vy * t - g * t * t / 2;
}

//a??????lb???ub????????? 
int cmp(double lb, double ub, double a){
	return a < lb + EPS ? -1 : a > ub - EPS ? 1 : 0;
}


//??????????°???????????????????(qx, qy)??¶,????????????????????? 
bool check(double qx, double qy){
 	/*  ??????????????¨x?????????y????????????????????????vx???vy,?????????(qx, qy)?????¶??´???t 
 		?±??§£??????????¨????vx^2 + vy^2 = V^2, vy * t = qx, vy * t - 1/2 g t^2 = qy
 		
		Vx^2 + Vy^2 = V^2;
		Vx*t = Qx;
		Vy*t - 1/2*g*t^2 = Qy;
		
		???x = t^2
		1/4*g^2*x^2 + (g*Qy - V^2)*x + Qx^2 + Qy^2 = 0;
		a = 1/4*g^2   b = g*Qy - V^2   c = Qx^2 + Qy^2
		
	*/
 	double a = g * g / 4,  b = g * qy - V * V, c = qx * qx + qy * qy;
 	double D = b * b - 4 * a * c;
 	if(D < 0 && D > -EPS) D = 0;									
 	if(D < 0) return false;											//????§£ 
 	for(int d = -1; d <= 1; d += 2){								//????????????????¨??????????????§£????????? 
 		double t2 = (-b + d * sqrt(D)) / (2 * a);					
 		if(t2 <= 0) continue;
 		double t = sqrt(t2);
 		double vx = qx / t, vy = (qy + g * t * t / 2) / t;
 		
 		//??????????????????????????£??????
        double yt = calc(vy, X / vx);
        if (yt < Y - EPS)
            continue;

        bool ok = true;
        for (int i = 0; i < N; i++){
            if (L[i] >= X)
                continue;
            //????????¨?????£???????????????????????´?????????????¢????
            if (R[i] == X && Y <= T[i] && B[i] <= yt)
                ok = false;
            //????????¨?£???°????????£??????????????????????????°????¢????
            int yL = cmp(B[i], T[i], calc(vy, L[i] / vx));   //?????§???????????????
            int yR = cmp(B[i], T[i], calc(vy, R[i] / vx));   //?????§???????????????
            int xH = cmp(L[i], R[i], vx * (vy / g));      //????????????????????????
            int yH = cmp(B[i], T[i], calc(vy, vy / g));
            if (xH == 0 && yH >= 0 && yL < 0)
                ok = false;
            if (yL * yR <= 0)
                ok = false;
        }
        if (ok)
            return true;
	}
 	return false;
}
 
void solve(){
	//???????????\??????????¢???? 
 	for(int i = 0; i < N; i++){
 		R[i] = min(R[i], X);
	}
	bool ok = check(X, Y);			//??´??\?????????????????? 
	for(int i = 0; i < N; i++){
	 	ok |= check(L[i], T[i]);	//?????????????§?????????? 
	 	ok |= check(R[i], T[i]);	//?????????????§?????????? 
	}
	puts(ok ? "Yes" : "No");
}
 
int main(){
 	while(scanf("%d%lf%lf%lf",&N,&V,&X,&Y)!=EOF){
 		for(int i = 0; i < N; i++)
 			scanf("%lf%lf%lf%lf",&L[i],&B[i],&R[i],&T[i]);	
		solve();
	}
 	return 0;
}

Measured memory_bytes: 2756
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X=input()

    x=int(X,2)
    pop_X=bin(x).count("1")

    pm1 = x % (pop_X-1) if pop_X-1 else 0
    pp1 = x % (pop_X+1)
    
    for i in range(N):
        sign = 1
        pop_Xi = pop_X
        if X[i] == "1": 
            sign *= -1
            pop_Xi -= 1
            _x = pm1
        else:
            pop_Xi += 1
            _x = pp1
        
        if pop_Xi == 0:
            print(0)
            continue
        
        
        two = pow(2,N-1-i,pop_Xi)
        X_i = _x + sign * two
        X_i %= pop_Xi
        count = 1
        while X_i:
            pop_Xi = bin(X_i).count("1")
            X_i = X_i % pop_Xi
            count += 1

        print(count)



if __name__ == "__main__":
    main()

Measured memory_bytes: 81924
#include "bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	int d[110]={0};
	for(int i=0;i<n;i++)cin>>d[i];

	int cnt=1;
	sort(d, d+n);
	for(int i=1;i<n;i++){
		if(d[i-1] < d[i]) cnt++;
	}

	cout<< cnt <<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(void){
	
	string s;
	int min=10000000;
	cin>>s;
	for(int i=0;i<s.length()-2;i++){
		int num=int(s[i]-'0')*100+int(s[i+1]-'0')*10+int(s[i+2]-'0');
		if(abs(num-753)<min){
			min=abs(num-753);
		}
	}
	cout<<min<<endl;
	return 0;
}

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

using namespace std;

int main(){
    vector<int> v;
    int n,k;
    scanf("%d %d",&n,&k);
    for (int i = 0; i < n; i++){
        int x;
        scanf("%d",&x);
        v.push_back(x);
    }
    std::sort(v.begin(),v.end());
    int r = 0;

    for (int i = 0; i < k; i++){
        r += v[n-1];
        n = n -1;
    }
    printf("%d",r);
}

Measured memory_bytes: 256
'''
制約
1≦N,A,B≦10^9
N  = 1の時ABもない

A < B
B < A
'''
N, A, B = map(int,input().split())

if A > B:
    print(0)
    exit()
elif N == 1 and A != B:
    print(0)
    exit()
else:
    min_sum = A * (N - 1) + B
    max_sum = A + B * (N - 1)

    ans = max_sum - min_sum + 1

    print(ans)


Measured memory_bytes: 3060
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
ans=0
for x in range(1,int(N**0.5)+1000):
    if (N-x)%x==0:
        m=(N-x)//x
        if m<=x:
            break
        ans+=m
print(ans)

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int num = 0;
    int maxnum = 0;
    int maxindex = 0;
    for (int i = 0; i < N; ++ i){
        if (S[i] == 'E'){
            num += 1;
            if (num > maxnum){
                maxnum = num;
                maxindex = i;
            }
        } else {
            num -= 1;
        }
    }
    int people = 0;
    for (int i = 0; i < maxindex; ++i ){
        if ( S[i] == 'W' ){
            people += 1;
        }
    }
    for (int i = maxindex + 1; i < N; ++i){
        if ( S[i] == 'E' ){
            people += 1;
        }
    }
    cout << people << endl;
    return 0;
}

Measured memory_bytes: 900
#include <stdio.h>
int main(){
  int n,fl=1;
  long max;
  long *h;
  scanf("%d",&n);
  h=(long*)malloc(n*sizeof(long));
  for (int i=0;i<n;i++) scanf("%ld",&h[i]);
  max=h[0];
  for (int i=1;i<n;i++){
    if (h[i]>max){
      max=h[i];
      continue;
    }
    if(max>h[i]+1){
      fl=0;
      break;
    }
  }
  free(h);
  
  if (fl) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll a, b, c; cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0) cout << 0 << endl;
    else {
        ll ans = min(a*b,min(b*c,a*c));
        cout << ans << endl;
    }

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  int m,n;
  cin>>m>>n;
  vector<string> t(m);
  REP(i,m)cin>>t[i];
  vector<int> iv,jv;
  REP(i,m) {
    bool al = true;
    REP(j,n) if(t[i][j] != '.') al = false;
    if(!al){
      if(i) iv.push_back(i-1);
      iv.push_back(i);
      if(i<m-1) iv.push_back(i+1);
    }
  }
  sort(begin(iv),end(iv));
  iv.erase(unique(begin(iv),end(iv)),end(iv));
  REP(i,n) {
    bool al = true;
    REP(j,m) if(t[j][i] != '.') al = false;
    if(!al){
      if(i) jv.push_back(i-1);
      jv.push_back(i);
      if(i<n-1) jv.push_back(i+1);
    }
  }
  sort(begin(jv),end(jv));
  jv.erase(unique(begin(jv),end(jv)),end(jv));
  if (iv.empty()) {
    cout << 0 << endl;
    return 0;
  }
  vector<string> ct(iv.size());
  m = iv.size();
  n = jv.size();
  REP(i,m)
    REP(j,n)
      ct[i] += t[iv[i]][jv[j]];
  int score = 0;
  while(1){
    set<char> er;
    REP(i,m)REP(j,n){
      if (ct[i][j] != '.') continue;
      map<char, int> s;
      int di[]={1,0,-1,0};
      int dj[]={0,1,0,-1};
      REP(k,4){
        int l=1;
        while(1){
          int ni=i+di[k]*l;
          int nj=j+dj[k]*l;
          if(ni<0||nj<0||ni>=m||nj>=n) break;
          if(ct[ni][nj] != '.'){
            ++s[ct[ni][nj]];
            break;
          }
          ++l;
        }
      }
      for (auto p:s) {
        if(p.second == 2) er.insert(p.first);
      }
    }
    score += er.size()*2;
    if (er.empty()) break;
    REP(i,m)REP(j,n){
      if(er.count(ct[i][j]))
        ct[i][j] = '.';
    }
  }
  cout << score << endl;
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    //ランレングス符号化してみる？
    //いや、先頭から調理できる
    int u = 1; //状態変数Rなら0　Lなら1に変化する)
    ll count = 0;
    vector<ll> data;
    rep(i, s.size())
    {
        if (u == 1 && s[i] == 'R')
        {
            //以前までのカウントをどこかに入れておきたい。
            if (i != 0)
            {
                data.push_back(count);
                count = 0;
            }
            u = 0;
        }
        if (u == 0 && s[i] == 'L')
        {
            //以前までのカウントをどこかに入れておきたい。
            data.push_back(count);
            count = 0;
            u = 1;
        }
        count++;
    }
    vector<ll> nu(s.size());
    data.push_back(count); //最後のLの数

    //(indexが偶数のものがr,奇数のものがl)
    //2*data.size()/2;
    ll sum = 0;
    for (int i = 0; i < data.size() / 2; i++)
    {
        sum += data[2 * i];
        if ((data[2 * i] + data[2 * i + 1]) % 2 == 0)
        {
            //0から2*iまでにいくら数が出てきたかの値が欲しい。
            nu[sum - 1] = (data[2 * i] + data[2 * i + 1]) / 2;
            nu[sum] = (data[2 * i] + data[2 * i + 1]) / 2;
            sum += data[2 * i + 1];
        }
        else
        {                             //奇数の方
            if (data[2 * i] % 2 == 1) //Rが奇数の時
            {
                nu[sum - 1] = (data[2 * i] + data[2 * i + 1]) / 2 + 1;
                nu[sum] = (data[2 * i] + data[2 * i + 1]) / 2;
                sum += data[2 * i + 1];
            }
            else //Lが奇数の時
            {
                nu[sum - 1] = (data[2 * i] + data[2 * i + 1]) / 2;
                nu[sum] = (data[2 * i] + data[2 * i + 1]) / 2 + 1;
                sum += data[2 * i + 1];
            }
        }
    }
    for (ll x : nu)
    {
        cout << x << " ";
    }
}

Measured memory_bytes: 2292
#include <cstdio>
typedef long long lld;
const int MAXN = 55;
const int MOD = 1e9+7;
lld K;
int N;

struct Matrix {
  int data[MAXN][MAXN];

  int& at(int i, int j) { return data[i][j]; }

  Matrix& operator *= (Matrix other) {
    Matrix copy = *this;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        data[i][j] = 0;
        for (int k = 0; k < N; ++k) {
          int val = 1LL * copy.at(i, k) * other.at(k, j) % MOD;
          data[i][j] = (1LL * val + data[i][j]) % MOD;
        }
      }
    }
    return *this;
  }

  void identity() {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        data[i][j] = (i == j) ? 1 : 0;
      }
    }
  }

  Matrix pow(lld exp) {
    Matrix ret;
    ret.identity();
    while (exp) {
      if (exp & 1LL) {
        ret *= *this;
      }
      *this *= *this;
      exp /= 2;
    }
    return ret;
  }

  int sum() const {
    int ans = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        ans = (1LL * data[i][j] + ans) % MOD;
      }
    }
    return ans;
  }
} A;

int main() {
  scanf(" %d%lld", &N, &K);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%d", &A.at(i, j));
    }
  }
  printf("%d\n", A.pow(K).sum());
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const long long mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

char f[30][30];
int w,h;
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};
int ans;

void dfs(int x,int y)
{
    f[y][x] = '#';
    ans++;
    for(int i = 0; i < 4; i++){
        int ny = y+dy[i];
        int nx = x+dx[i];
        if(ny >= 0 && ny < h && nx >= 0 && nx < w && f[ny][nx] == '.'){
            dfs(nx,ny);
        }
    }
    return ;
    
}

int main()
{
    while(true){
        cin >> w >> h;
        ans = 0;
        if(w == 0 && h == 0) break;
        int sx,sy;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> f[i][j];
                if(f[i][j] == '@'){
                    sx = j;
                    sy = i;
                }
            }
        }
        dfs(sx,sy);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3048
def main():
    K = int(input())
    num = 7%K
    ans = 0
    # print(num)
    for i in range(K):
        ans += 1
        if num%K == 0:
            print(ans)
            return
        num = (num*10 +7)%K

    print(-1)
    return

main()

Measured memory_bytes: 9012
#include<iostream>
#include<algorithm>
#include<cstring>
#define INF (1<<29)
using namespace std;

int n,h,a[1005],b[1005];
int dp[1005][10005];

int f(int pos,int heart){
  if(pos==n)return INF;
  if(heart<=0)return 0;
  if(dp[pos][heart]!=-1)return dp[pos][heart];
  
  return dp[pos][heart]=min(f(pos,heart-a[pos])+b[pos],f(pos+1,heart));
  
}

int main(){
  cin>>h>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }

  memset(dp,-1,sizeof(dp));
  
  cout<<f(0,h)<<"\n";
  
  return 0;
}


Measured memory_bytes: 40064
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#include<bits/stdc++.h>
#include<cstdlib>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds; 
//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef long double ld;
typedef vector < pair < ll, ll > > vpll;
#define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define forn(i,n) for (ll i = 0; i < n; i++)
#define fo(i,n) for (ll i = 1; i <= n; i++)
#define fore(i,l,r) for (ll i = l; i <= r; i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
//#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define MAX 1000000007
#define N 2000009
#define N1 100007
ll power(ll a,ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fact[500009];
ll fermat_inv(ll y){return power(y,MOD-2);}
ll nCrMod(ll n, ll r){ ll p=fact[n];ll q=(fact[r]*fact[n-r])%MOD;return (p*fermat_inv(q))%MOD;} 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
const ld PI = acos(-1.0);
vl g[N1];


  int main(){
      #ifndef ONLINE_JUDGE
      freopen("input.cpp","r",stdin);
      freopen("output.cpp","w",stdout);
      #endif
      Boost();
      int t;
      //cin>>t;
      t=1;
      int t1=t;
      while(t--)
      {
        ll n;
        cin>>n;
        if(n%1000)
          cout<<1000-n%1000<<endl;
        else
          cout<<0<<endl;
      }
      return 0;
  }

Measured memory_bytes: 6000
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define MAX 150
using namespace std;

bool dp[MAX][MAX][2];
 
int main()
{
  int T;
  while(cin >> T)
    {
      while(T--)
	{
	  rep(i,MAX)rep(j,MAX)rep(l,2)dp[i][j][l] = false;
	  int N;
	  cin >> N;
	  int input[N];
	  rep(i,N) cin >> input[i];
       
	  if(N <= 2)
	    {
	      cout << input[N-1] << endl;
	      continue;
	    }
       
	  int ans = input[N-1];
 
	  REP(cur,1,N-1)
	    {
	      dp[input[cur-1]][input[cur]][cur&1] = true;
	      int R = input[cur+1];
	      rep(L,MAX)
		{
		  rep(M,MAX)
		    {
		      if(!dp[L][M][cur&1])continue;
		      //cout << cur << " cur(" << L << "," << M << "," << R << ")\n";
		      if(M == 0)
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			    }
			  else       ans = max(ans,R);
			}
		      else
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			      dp[M-1][R+L][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M-1 << "," << R+L << "," << input[cur+2] << ")\n";
			    }
			  else 
			    {
			      ans = max(ans,R+L);
			      //cout << cur << " ans : " << R << "+" << L << "=" << R+L <<  " (" << L << "," << M << "," << R << ")" <<  endl;
			    }
			}
		    }
		}
	      rep(i,MAX)rep(j,MAX)dp[i][j][cur&1] = false;
	    }
	  
	  cout << ans << endl;      
	}
    }
  return 0;
}

Measured memory_bytes: 1204