akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	static String strArray[];
	static int re=0, hishi=0;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;

		while(null != (str=br.readLine())){
			strArray = str.split(",");
			box();
		}

		System.out.println(re);
		System.out.println(hishi);

	}

	static void box(){
		int l1 = Integer.parseInt(strArray[0]);
		int l2 = Integer.parseInt(strArray[1]);
		int t = Integer.parseInt(strArray[2]);

		if(l1 == l2){
			hishi++;
		}else if((Math.pow(l1, 2) + Math.pow(l2, 2)) == Math.pow(t, 2)){
			re++;
		}

	}

}

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

int cnt[10];

int main(){
    for (int i = 0, x; i < 4; ++ i){
        scanf("%d", &x);
        ++ cnt[x];
    }
    if (cnt[1] == 1 && cnt[4] == 1 && cnt[7] == 1 && cnt[9] == 1){
        puts("YES");
    }
    else{
        puts("NO");
    }
    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//printfを使うときはこれでエラーになるので注意,下を削除
struct all_init {
  all_init() {
    cout.tie(nullptr);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(11);
  };
} ALL_INIT;
//printfを使うときは上を削除
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	int x,y;
	cin >> x >> y;
	int ans = 0;
	if(x<=3){
		ans += (4-x) * 100000;
	}
	if(y<=3){
		ans += (4-y) * 100000;
	}
	if(x==1 && y==1){
		ans += 4 * 100000;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<array>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[n],count[n+1] ;
  for(int i=0;i<n+1;i++){
    count[i]=0;
  }
  for(int i=0;i<n-1;i++){
    cin>>arr[i];
    count[arr[i]]++;
  }
  for(int i=1;i<=n;i++){
    cout<<count[i]<<"\n";
  }
  return 0;
}

Measured memory_bytes: 5188
c = [ list(map(int, input().split())) for _ in range(3)]

ans = 'Yes'

b1 = c[0][0]
b2 = c[0][1]
b3 = c[0][2]

a1 = 0
a2 = c[1][0] - b1
a3 = c[2][0] - b1

if (a2 + b2 != c[1][1]) or (a2 + b3 != c[1][2]) or (a3 + b2 != c[2][1]) or (a3 + b3 != c[2][2]):
    ans = 'No'

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}
template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    vi a(3);
    REP(i,3) cin >> a[i];
    sort(a.begin(), a.end());
    int A = a[0], B = a[1], C = a[2];
    int count = 0;
    count += (C - A) / 2; 
    A += ((C-A)/2) * 2;
    count += (C -B) / 2;
    B += (C-B) / 2 * 2;
    if( A == C && B == C){
        cout << count << endl;
    }else if ( A == C){
        cout << count + 2 << endl;
    }else if( B == C){
        cout << count + 2 << endl;
    }else{
        cout << count + 1 << endl;
    }
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 1000000007
#define MAX 10005
#define ll long long
int x[MAX];
int map[MAX][MAX];
int n,m,r;
void floyed()
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        for(int k=1;k<=n;k++)
    {
        map[j][k]=min(map[j][i]+map[i][k],map[j][k]);
    }
}
int main()
{
    int u,v,w;
    scanf("%d%d%d",&n,&m,&r);
    for(int i=0;i<r;i++)
        scanf("%d",&x[i]);
    sort(x,x+r);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(i!=j)
            map[i][j]=INF;
        else
            map[i][j]=0;
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        map[u][v]=map[v][u]=min(map[u][v],w);
    }
    floyed();
    int minn=INF;
    do{
        int sum=0;
        for(int i=1;i<r;i++)
            sum+=map[x[i-1]][x[i]];
        minn=min(minn,sum);
    }while(next_permutation(x,x+r));
    printf("%d\n",minn);
    return 0;
}


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

int s2i(string s){
  stringstream ss;
  int res;
  ss<<s;
  ss>>res;
  return res;
}

int m,n;
map<string,int> t;
int l[100],r[100];


vector<int> change(int x){
  vector<int> res(256);
  for(int i=l[x];i<=r[x];i++)res[i]=1;
  return res;
}

vector<int> change(string s){
  vector<int> res(256);
  res[s2i(s)]=1;
  return res;
}

bool solve(){
  string str,tmp;
  getline(cin,str);
  stringstream ss(str);

  stack< vector<int> > st;
  
  while(ss>>tmp){
    if(tmp=="+"){
      vector<int> a,b,c;
      b=st.top();st.pop();
      a=st.top();st.pop();
      c.resize(256);
      for(int i=0;i<256;i++){
        if(a[i]==0)continue;
        for(int j=0;j<256;j++){
          if(b[j]==0)continue;
          c[(i+j)%256]=1;
        }
      }
      st.push(c);
    }else if(tmp=="-"){
      vector<int> a,b,c;
      b=st.top();st.pop();
      a=st.top();st.pop();
      c.resize(256);
      for(int i=0;i<256;i++){
        if(a[i]==0)continue;
        for(int j=0;j<256;j++){
          if(b[j]==0)continue;
          c[(i-j+256)%256]=1;
        }
      }
      st.push(c);
    }else if(tmp=="*"){
      vector<int> a,b,c;
      b=st.top();st.pop();
      a=st.top();st.pop();
      c.resize(256);
      for(int i=0;i<256;i++){
        if(a[i]==0)continue;
        for(int j=0;j<256;j++){
          if(b[j]==0)continue;
          c[(i*j)%256]=1;
        }
      }
      st.push(c);
    }else if(tmp=="/"){
      vector<int> a,b,c;
      b=st.top();st.pop();
      a=st.top();st.pop();
      c.resize(256);
      for(int i=0;i<256;i++){
        if(a[i]==0)continue;
        for(int j=0;j<256;j++){
          if(b[j]==0)continue;
          if(j==0)return false;
          c[i/j]=1;
        }
      }
      st.push(c);
    }else if(t.count(tmp)){
      st.push( change( t[tmp] ) );
    }else{
      st.push( change(tmp) );
    }
  }
  
  return true;
}

int main(){
  cin>>m;
  for(int i=0;i<m;i++){
    string s;
    cin>>s>>l[i]>>r[i];
    t[s]=i;
  }
  cin>>n;
  cin.ignore();
  cout<<(solve()?"correct":"error")<<endl;
  return 0;
}

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

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

int comp(string s, string t){
  int same = 0;
  for(int i = 0; i<s.length(); ++i){
    if(s[i] == t[i]) ++same;
  }
  return same;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >>s>>t;
  int slen = s.length();
  int tlen = t.length();
  int ans = 0;
  for(int i=0; i<=slen-tlen; ++i){
    ans = max(ans, comp(s.substr(i, tlen), t));
  }
  cout << tlen - ans << endl;

  return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,d;
double a[101][101];
inline int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='0')f=!f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f?-x:x;
}

int main(){
    int sum=0;
    n=read(),d=read();
    for(int i=1;i<=n;++i){
        for(int j=1;j<=d;++j){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            double ans=0;
            for(int k=1;k<=d;++k){
                ans+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            ans=sqrt(ans);
            int qwq=int(ans);
            if(qwq==ans) sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
# Aizu Problem ITP_1_2_D: Circle in an Rectangle
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input3.txt", "rt")

def circle_in_rectangle(W, H, x, y, r):
    return W >= 2 * r and x >= r and x <= W - r and \
           H >= 2 * r and y >= r and y <= H - r
    
W, H, x, y, r = [int(_) for _ in input().split()]
print("Yes" if circle_in_rectangle(W, H, x, y, r) else "No")

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

int main() {
  int x, y; cin >> x >> y;
  bool exist = false;
  for (int i = 0; i <= x; i++) {
    if (2*i + 4*(x - i) == y) exist = true;
  }
  if (exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
/**
 * @author torith
 * @date 2019-01-12
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, H, W;
    cin >> N >> H >> W;

    cout << (N - H + 1) * (N - W + 1) << "\n";

    return 0;
}



Measured memory_bytes: 256
#N,K入力
n,k= map(int,input().split())

ans = 0

for i in range(k,n+2):
    #min = (i-1)*i/2
    #max = (2*n-i+1)*i/2
    ans += i*(n-i+1)+1 #max - min +1

print(ans % (10**9 + 7))

Measured memory_bytes: 9064
#!/usr/bin/env python3
def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    lst = [0] * (N + 1)
    for a in A:
        lst[a] += 1
    for i in lst[1:]:
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32284
#include <cstdio>
int main() {
	int n, m;
	const int mmax = 50, nmax = 50;
	char A[nmax][nmax], B[mmax][mmax];
	scanf("%d%d", &n, &m);
	for (int y = 0; y < n; y++)scanf("%s", &A[y]);
	for (int y = 0; y < m; y++)scanf("%s", &B[y]);
	bool exist = false;
	for (int ly = 0; ly < n; ly++)for (int lx = 0; lx < n; lx++) {
		if (lx + m - 1 >= n or ly + m - 1 >= n) continue;
		bool flag = true;
		for (int y = 0; y < m; y++)for (int x = 0; x < m; x++) {
			if (A[ly + y][lx + x] != B[y][x]) flag = false;
		}
		if (flag)exist = true;
	}
	if (exist) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
W = [input() for _ in range(N)]

a = []
pre = W[0]
a.append(pre)
flag = False
for wi in W[1:]:
    if wi in a or pre[-1] != wi[0]:
        flag = True
        break
    pre = wi
    a.append(wi)
        
if flag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, ans = 0, sum = 0; cin >> n >> m;
    int array[2][n]; 
    for(int i = 0; i < 2; ++i)
        for(int j = 0; j < n; ++j)
            array[i][j] = 0;

    for(int i = 0; i < m; ++i){
        int x; string s; cin >> x >> s;
        if(s == "WA"){
            if(array[1][x-1] == 0)
                array[0][x-1]++;
        }else{
            if(array[1][x-1] == 0){
                ans++;
                sum += array[0][x-1];
            }
            array[1][x-1] = 1;
        }
    }
    cout << ans << ' ' << sum;
}


Measured memory_bytes: 1024
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

div = make_divisors(N)
div2 = div.copy()
div2.reverse()
n = len(div2)//2
print(max(len(str(div[n])), len(str(div2[n]))))

Measured memory_bytes: 3188
if __name__ == '__main__':
    s = list(input())
    rev_s = list(reversed(s))
    ans = 0
    l, r = 0, len(s) - 1

    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == 'x':
            l += 1
            ans += 1
        elif s[r] == 'x':
            r -= 1
            ans += 1
        else:
            print(-1)
            exit(0)
    print(ans)


Measured memory_bytes: 4788
// Gracias, Rodolfo
// Gracias, MarcosK
// Gracias, Graphter
// Obrigado, Dilson
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for (Long i = a; i < b; i++)
#define roF(i,a,b) for (Long i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long Long;
typedef long double Double;
typedef unsigned long long ULong;
typedef pair<Long, Long> Pair;
typedef vector<Long> Vector;
typedef vector<Pair> PairVector;

const int N = 1e6;
const Long INF = 1e9;
const Double EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
Long random(Long a, Long b) { return uniform_int_distribution<Long> (a, b) (rng); }

void solve() {
	Long n, m;
	cin >> n >> m;
	Long lim = 1 << n;
	Long dp[lim];
	For(i, 0, lim) dp[i] = INF;
	dp[0] = 0;
	For(i, 0, m) {
		Long value, boxes;
		cin >> value >> boxes;
		bool unlock[n];
		For(j, 0, n) unlock[j] = false;
		For(j, 0, boxes) {
			Long pos;
			cin >> pos;
			unlock[pos - 1] = true;
		}
		Long temp[lim];
		For(mask, 0, lim) temp[mask] = dp[mask];
		For(mask, 0, lim) {
			bool cur[n];
			Long copy = mask;
			For(j, 0, n) {
				cur[n - 1 - j] = (copy % 2 == 0 ? false : true) or unlock[n - 1 - j];
				copy /= 2;
			}
			Long who = 0;
			Long pot = 1;
			For(j, 0, n) {
				if (cur[n - 1 - j]) who += pot;
				pot *= 2;
			}
			temp[who] = min(temp[who], dp[mask] + value);
		}
		For(mask, 0, lim) dp[mask] = temp[mask];
	}
	if (dp[lim - 1] >= INF) cout << "-1" << endl;
	else cout << dp[lim - 1] << endl;
}

int main() {
	fastio;
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 3680
import java.util.*

fun main(args: Array<String>) {
    val dic = mutableMapOf<String, Int>()
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    repeat(n) {
        val s = sc.next()
        dic[s] = (dic[s] ?: 0) + 1
    }

    val m = sc.nextInt()
    repeat(m) {
        val t = sc.next()
        dic[t] = (dic[t] ?: 0) - 1
    }

    println(Math.max(0, dic.values.max() ?: 0))
}


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

int main(){

    int tmp[11] = {};
    rep(i, 3){
        int t;
        cin >> t;
        tmp[t]++;
    }
    if(tmp[5]==2 && tmp[7]==1)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

char c;

int main() {
	cin >> c;
	if (c == 'A')cout << 'T' << endl;
	if (c == 'T')cout << 'A' << endl;
	if (c == 'G')cout << 'C' << endl;
	if (c == 'C')cout << 'G' << endl;
}


Measured memory_bytes: 256
//形状データ処理

#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<set>

using namespace std;
#define LL long long

int N;
set<LL> p;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		LL tmp = 0;
		tmp += max(a, max(b, c));
		tmp += 10000 * (a + b + c - max(a, max(b, c)) - min(a, min(b, c)));
		tmp += 100000000 * min(a, min(b, c));
		p.insert(tmp);
	}
	cout << N - p.size() << endl;

	return 0;
}


Measured memory_bytes: 3140
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M, K = in.next().toLong

  val MOD = 1e9.toLong + 7

  var ans = 0L

  val combN = (N*M - 2).toInt

  val mc = new ModComb(combN, MOD)

  def calc(x: Long, y: Long, dist: Long): Long = {
    var res = y*y * (x-dist)
    res %= MOD
    res *= mc.comb(combN, K.toInt - 2)
    res %= MOD
    res *= dist
    res %= MOD

    res
  }

  for (dist <- 1 to (N-1).toInt) {
    ans += calc(N, M, dist)
    ans %= MOD
  }

  for (dist <- 1 to (M-1).toInt) {
    ans += calc(M, N, dist)
    ans %= MOD
  }

  println(ans)
}

class ModComb(maxNum: Int, mod: Long) {

  private def repeatSquares(x: Long, n: Long): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % mod, n/2)
    else
      (x * repeatSquares(x*x % mod, n/2)) % mod
  }

  private val fact = new Array[Long](maxNum + 1)

  fact(0) = 1
  for (i <- 1 to maxNum)
    fact(i) = (i * fact(i-1)) % mod

  private val factInv = new Array[Long](maxNum + 1)

  factInv(maxNum) = repeatSquares(fact(maxNum), mod-2)
  for (i <- (1 to maxNum).reverse)
    factInv(i-1) = (i * factInv(i)) % mod


  // nCk
  def comb(n: Int, k: Int): Long = {
    val numer = fact(n)
    val denom = (factInv(n-k) * factInv(k)) % mod

    (numer * denom) % mod
  }

}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}


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

int fn(int x)
{
    int c=0;
    while((x&1)==0)
    {
        c++;x=x>>1;
    }
    return c;
}


int main()
{
    int i,d,j,k,n,m;
    cin>>n;
    int c=0;
    for(i=0;i<n;i++)
    {
        int a;cin>>a;
        c+=fn(a);
    }
    cout<<c;

}


Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final long INF = 0x3f3f3f3f3f3f3f3fL;
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] ii = new int[m];
		int[] jj = new int[m];
		int[] ww = new int[m];
		for (int h = 0; h < m; h++) {
			ii[h] = sc.nextInt() - 1;
			jj[h] = sc.nextInt() - 1;
			ww[h] = sc.nextInt();
		}
		long[] dp = new long[n]; Arrays.fill(dp, -INF); dp[0] = 0;
		for (int k = 1; k <= n * 2; k++) {
			boolean updated = false;
			for (int h = 0; h < m; h++) {
				int i = ii[h], j = jj[h];
				if (dp[i] != -INF) {
					long d = dp[i] + ww[h];
					if (dp[j] < d) {
						dp[j] = d;
						if (j == n - 1)
							updated = true;
					}
				}
			}
			if (updated && k >= n) {
				println("inf");
				return;
			}
		}
		println(dp[n - 1]);
	}
}


Measured memory_bytes: 43096
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")



// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
// initialize: UnionFind UF(N)

class UnionFind {                                              // OOP style
private:
	vector<int> p, rank, setSize;
	// p = path toward the root of disjoint set; p[i] = i means it is root
	// rank = upper bound of the actual height of the tree; not reliable as accurate measure
	// setSize = size of each disjoint set

	int numSets;
public:
	UnionFind(int N) {
		setSize.assign(N, 1);
		numSets = N;
		rank.assign(N, 0);
		p.assign(N, 0);
		for (int i = 0; i < N; i++) p[i] = i;	// each belongs to its own set
	}

	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));		// path compression: cut short of the path if possible
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void unionSet(int i, int j) {
		if (!isSameSet(i, j)) {
			numSets--;
			int x = findSet(i), y = findSet(j);
			// rank is used to keep the tree short
			if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
			else {
				p[x] = y; setSize[y] += setSize[x];
				if (rank[x] == rank[y]) rank[y]++;
			}
		}
	}

	int numDisjointSets() {		// # of disjoint sets
		return numSets;
	}

	int sizeOfSet(int i) {		// size of set
		return setSize[findSet(i)];
	}
};


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

	int n, m, a, b, i, j, k, ans;

	cin >> n >> m;
	UnionFind uf(n);
	while (m--) {
		cin >> a >> b;
		uf.unionSet(a - 1, b - 1);
	}
	ans = uf.numDisjointSets() - 1;
	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 4472
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;


main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll x, y;
    cin >> x >> y;
    ll ans  = 0;
    if(x <= 3)  ans += (4ll - x) * 100000ll;
    if(y <= 3)  ans += (4ll - y) * 100000ll;
    if(x == 1 and y == 1)   ans += 400000;
    cout << ans;
}

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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d) {
    cout << "Yes" << endl;
  }
  else if (abs(a - b) <= d) {
    if (abs(b - c) <= d) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int64 N;
  cin >> N;
  vector<PLL> AB(N);
  REP(i, N) cin >> AB[i].sc >> AB[i].fs;
  sort(all(AB));
  int64 now = 0;
  REP(i, N) {
    now += AB[i].sc;
    if (now > AB[i].fs) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3456
//20200815C
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x=sc.nextLong();
		long k=sc.nextLong();
		long d=sc.nextLong();
		if(x<0){
			x=-x;
		}
		if(k%2==1){
			x=x-d;
		}
		k=k/2;
		d=2*d;
		if(x<0){
			x=-x;
		}
		long w=x/d;
		long ans;
		if(w>k){
			ans=x-d*k;
          	
		}else{	
			long t1=x-d*w;
			long t2=d-t1;
			if(t1<t2){
				ans=t1;
              //	System.out.println("a");
			}else{
				ans=t2;
             // 	System.out.println("b");
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35764
#include <stdio.h>
#define N 200000
int main(){
  int a[N],i,j,k;
  int minv,maxv;
  scanf("%d",&k);
  for(i=0;i<k;i++){
  scanf("%d",&a[i]);
  }
  maxv=a[1]-a[0];
  minv=a[0];
  for(j=1;j<k;j++){
    if(maxv<a[j]-minv)
      maxv=a[j]-minv; 
      if(minv>a[j])
      minv=a[j];
  }
  printf("%d\n",maxv);
  return 0;
}
      


Measured memory_bytes: 2516
#include <stdio.h>

int main(void) {
	double a,b,c,d,e,f,x,y;
	while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
		y=(d*c-a*f)/(d*b-a*e);
        printf("%.3f %.3f\n",(c-b*y)/a, y);
	}
	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <string>
#include <vector>
//#include <map>
using namespace std;

bool check(string s){
    char f = s[0];
    for(char x : s)
        if(f != x)
            return false;
    return true;
}
int main(void){
    string s;
    cin >> s;
    int count = 0;
    // while (!check(s))
    // {
    //     ++count;
    //     char f = s[0];
    //     char r = (f=='W')?'B':'W';
  
        
    //     for(int i =0; i < s.length();i++){
    //         if(s[i] == r)
    //             break;
    //         else
    //         {
    //             s[i] = r;
    //         }
            
    //     }
    // }
    // cout << count;
    char flag = s[0];
    for(char x : s){
        if(x != flag){
            count++;
            flag = x;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 512
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def keta(n):
    a = 0
    while (n > 0):
        a += 1
        n = n//10
    return a

n = int(input())

ans=0
for x in range(1,n+1):
    if keta(x) % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 40940
#include<stdio.h>
#include <iostream>
#include<string>
#include <algorithm>

using namespace std;

int main()
{
	
	long long num[2];
	long long tmp;

	cin >> num[0] >> num[1];

	tmp = num[0] % num[1];


	cout << min(tmp,num[1]-tmp);
	
	return 0;

}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
ans=[]
def dame():
  print("No")
  exit()

n,A,B,C = map(int,input().split())
S = [input() for i in range(n)]
for i in range(n-1):
  si = S[i];sii = S[i+1]
  if si == "AB":
    if A == 0 and B == 0:dame()
    elif A == 0 or B >= 2:A+=1;ans.append("A");B-=1
    elif B == 0 or A >= 2:A-=1;B+=1;ans.append("B")
    else:
      if sii == "AC":
        A+=1;ans.append("A");B-=1
      else:
        A-=1;B+=1;ans.append("B")

  if si == "AC":
    if A == 0 and C == 0:dame()
    elif A == 0 or C >= 2:A+=1;ans.append("A");C-=1
    elif C == 0 or A >= 2:A-=1;C+=1;ans.append("C")
    else:
      if sii == "AB":
        A+=1;ans.append("A");C-=1
      else:
        A-=1;C+=1;ans.append("C")

  if si == "BC":
    if C == 0 and B == 0:dame()
    elif C == 0 or B >= 2:C+=1;ans.append("C");B-=1
    elif B == 0 or C >= 2:C-=1;B+=1;ans.append("B")
    else:
      if sii == "AC":
        C+=1;ans.append("C");B-=1
      else:
        C-=1;B+=1;ans.append("B")

si = S[n-1]
if si == "AB":
  if A == 0 and B == 0:dame()
  elif A == 0 or B >= 2:A+=1;ans.append("A");B-=1
  else:A-=1;B+=1;ans.append("B")
if si == "AC":
  if A == 0 and C == 0:dame()
  elif A == 0 or C >= 2:A+=1;ans.append("A");C-=1
  else:A-=1;C+=1;ans.append("C")
if si == "BC":
  if C == 0 and B == 0:dame()
  elif C == 0 or B >= 2:C+=1;ans.append("C");B-=1
  else:C-=1;B+=1;ans.append("B")


print("Yes")
print(*ans,sep="\n")

Measured memory_bytes: 91388
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<cstring>
#include <cstdio>
#include<cmath>

typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main ()
{
    int r;
    cin>>r;
    cout<<r*r<<endl;

    return 0;
}



Measured memory_bytes: 256
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#location: w,hで記載
def main():
	n = int(input())
	a = list(map(int,input().split()))
	ans=0
	for i in a:
		while i%2==0:
			ans+=1
			i/=2
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Measured memory_bytes: 43884
import sys
sys.setrecursionlimit(10**6)


inf = float('Inf')
f = [2, 3, 5]
cost = [0]*4


d = dict()


def dfs(x, d):
    if x in d:
        return(d[x])
    ret = cost[-1]*x
    for i in range(3):
        if x < f[i]:
            continue
        if x % f[i] == 0:
            ret = min(ret, dfs(x // f[i], d) + cost[i])
        else:
            k = x // f[i]
            ret = min(ret, cost[i] + dfs(k, d) + (x %
                                                  f[i]) * cost[-1], cost[i] + dfs(k+1, d) + ((k+1)*f[i]-x)*cost[-1])
    d[x] = ret
    return(ret)


def main():
    T = int(input())
    for _ in range(T):
        N, *c = map(int, input().split())
        for i in range(4):
            cost[i] = c[i]
        print(dfs(N, dict()))


main()


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 7;
const LL LINF = INF * INF;

const int mod = 1e9 + 7;
 
inline int add(int x, int y)
{
	if (x + y >= mod)
		return x + y - mod;
	return x + y;
}

inline int mult(int x, int y)
{
	return x * (LL) y % mod;
}

int n;
LL k;
vector<VI> a;

vector<VI> mult(vector<VI>& x, vector<VI>& y)
{
	vector<VI> res(n, VI(n, 0));
	FOR(i, 0, n)
		FOR(j, 0, n)
			FOR(k, 0, n)
				res[i][j] = add(res[i][j], mult(x[i][k], y[k][j]));
	return res;
}

void vyvid(vector<VI>& x)
{
	FOR(i, 0, n)
	{
		FOR(j, 0, n)
			cout << x[i][j] << ' ';
		cout << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n >> k;
	a.assign(n, VI(n, 0));
	FOR(i, 0, n)
		FOR(j, 0, n)
			cin >> a[i][j];
	
	vector<VI> r(n, VI(n, 0));
	FOR(i, 0, n)
		r[i][i] = 1;
	
	while(k)
	{
		if (k & 1)
			r = mult(r, a);
		a = mult(a, a);
		k >>= 1;
	//	vyvid(r);
	}
	

	int ans = 0;
	FOR(i, 0, n)
		FOR(j, 0, n)	
			ans = add(ans, r[i][j]);
	
	cout << ans << endl;	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 110;
bool a[N];

int main() {
  int n, m;
  cin >> n >> m;
  fill(a, a + n, false);
  for (int i = 0; i < m; ++i) {
    int len, x;
    cin >> len;
    for (int j = 0; j < len; ++j) {
      cin >> x;
      --x;
      a[x] = true;
    }
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) ret += !a[i];
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,A,B; cin >> N >> A >> B;
    ll out = 0;
    for(int i=1;i<=N;i++){
        int s=i/10000;
        int x=(i-s*10000)/1000;
        int y=(i-s*10000-x*1000)/100;
        int z=(i-s*10000-x*1000-y*100)/10;
        int w=i%10;
        cerr << s << x << y << z << w << endl;
        int r=s+x+y+w+z;
        if(A<=r && r<=B){
            out += i;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

using namespace std;

int main(void) {
    int h, w;
    cin >> h >> w;
    int ans[52][52];
    Fill(ans, 0);

    FOR(i, 1, h+1) {
        FOR(j, 1, w+1) {
            char input;
            cin >> input;
            if (input == '#') {
                ans[i-1][j-1] += 1;
                ans[i-1][j] += 1;
                ans[i-1][j+1] += 1;
                ans[i][j-1] += 1;
                ans[i][j] = -100;  // minus means a bomb
                ans[i][j+1] += 1;
                ans[i+1][j-1] += 1;
                ans[i+1][j] += 1;
                ans[i+1][j+1] += 1;
            }
        }
    }

    FOR(i, 1, h+1) {
        FOR(j, 1, w+1) {
            if (ans[i][j] < 0) {
                cout << "#";
            }
            else {
                cout << ans[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int n,a,b,u,x[101],h[101],y[101],cx,cy,H;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d%d",&x[i],&y[i],&h[i]); 
		if(h[i]!=0)u=i;
	}
	for(int xi=0;xi<=100;++xi)
      for(int yi=0;yi<=100;++yi)
		{
			cx=xi,cy=yi;
			H=h[u]+abs(x[u]-cx)+abs(y[u]-cy);
			for(int i=1;i<=n;++i)
			{
				if(h[i]!=std::max(H-std::abs(x[i]-cx)-std::abs(y[i]-cy),0))break;
				if(i==n)
				{
					printf("%d %d %d",cx,cy,H);
					return 0;
				}
			}
		}
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    S = input()
    if 'R' not in S:
        print(0)
    else:
        if S in set({'RRR'}):
            print(3)
        elif S in set({'RRS', 'SRR'}):
            print(2)
        else:
            print(1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 65252
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int h[n];
    long sum;

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

    sort(h, h + n, greater<int>());

    for (int i = 0; i < n; i++)
    {
      	if (i <= k - 1) h[i] = 0;
        sum += h[i];
    }
    cout << sum;

    return 0;
}

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

int main()
{
    string S, T;
    cin >> S >> T;

    int ans = 1005;
    for (size_t i = 0; i < S.size() - T.size() + 1; i++)
    {
        int count = 0;
        for (size_t j = 0; j < T.size(); j++)
        {
            if (S[i + j] != T[j])
            {
                count++;
            }
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n;
        int roop=0;
        StringBuilder[] ans=new StringBuilder[1000];
        String tmpData;
        while((n=sc.nextInt())!=0){
            String[][] str=new String[n][2];
            for(int j=0;j<n;j++){
                str[j][0]=sc.next();
                str[j][1]=sc.next();
            }
            int dn=sc.nextInt();
            for(int j=0;j<dn;j++){
                tmpData=sc.next();
                for(int k=0;k<n;k++){
                    if(tmpData.equals(str[k][0])){
                        tmpData=str[k][1];
                        break;
                    }
                }
                if(j==0){
                    ans[roop]=new StringBuilder(tmpData);
                }else{
                    ans[roop].append(tmpData);
                }
            }
            roop++;
        }
        sc.close();
        for(int i=0;i<roop;i++){
            System.out.println(ans[i].toString());
        }
    }
}

Measured memory_bytes: 69008
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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(){
    int n;cin>>n;
    while(n>0){
        if (n%10==7){
            cout<<"Yes"<<endl;
            return 0;
        }
        n/=10;

    }
    cout << "No" << endl;

}

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

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second


int N,M;
VI num;

int main(){

	cin >> N >> M;
	num.resize(N);
	REP(i,M){
		int a,b;
		cin >> a;
		cin >> b;
		num[a-1]++;
		num[b-1]++;
	}

	REP(i,N){
		cout << num[i] << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    printf("%.6f %d\n", double(W) * double(H) / 2, x * 2 == W && y * 2 == H);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
vll adj[100005];
int main()
{
    string s;
    cin>>s;
    ll n=s.size();
    ll c=0;
    rep(i,s.size()-1){
        if(s[i]!=s[n-i-2])
            c=1;
    }
    if(s[0]=='0'||s[n-1]=='1'||c==1){
        cout<<-1;
        return 0;
    }
    ll last=1;
    rep(i,s.size()-1){
        if(s[i]=='1'){
            adj[last].pb(i+2);
            last=i+2;
        }
        else
            adj[last].pb(i+2);
    }
    repA(i,1,n){
        rep(j,adj[i].size())
        cout<<i<<" "<<adj[i][j]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6912
import sys
input = sys.stdin.readline
#import numpy as np



def main():

    N,W = map(int,input().split())

    dp = [0] * (W+2)

    for _ in range(N):
        w,v = map(int,input().split())

        for j in range(W+1,w-1,-1):
            dp[j] =max(dp[j-w] +v ,dp[j])

    print(dp[W])



if __name__ == "__main__":
    main()


Measured memory_bytes: 65748