akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  int N;
  long long xx=1000000007;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int B[N+1];
  for(int i=0;i<N+1;i++){
    B[i]=0;
  }
  for(int i=0;i<N;i++){
    B[A[i]]++;
  }
  bool out=true;
  long long sum=1;
  if(N%2==0){

    for(int i=0;i<N+1;i++){
      if(i%2==0&&B[i]!=0){
        out=false;
      }
      if(i%2==1&&B[i]!=2){
        out=false;
      }
    }
    
    if(out){
      for(int i=0;i<N/2;i++){
        sum=sum*2%xx;
        
      }
      cout<<sum<<endl;

    }else{
      cout<<0<<endl;
    }
  }else{
    if(B[0]!=1){
      out=false;
    }
    for(int i=1;i<N+1;i++){
      if(i%2==1&&B[i]!=0){
        out=false;
      }
      if(i%2==0&&B[i]!=2){
        out=false;
      }
    }
    if(out){
      for(int i=0;i<N/2;i++){
        sum=sum*2%xx;
        

      }
      cout<<sum<<endl;

    }else{
      cout<<0<<endl;
    }



  }
  
  



}



  
  

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    int total = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        total += a[i];
    }
    total = ceil((.25 * total)/ m);
    for (int i = 0; i < n && m; i++) if (a[i] >= total) m--;
    if (m) puts("No");
    else puts("Yes");
    return 0;
}


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

using namespace std;

int main()
{
  int N,M;
  cin>>N;
  cin>>M;
  char mass;

  int frag_nw[50] ={0};
  int frag_nr[50] ={0};
  int frag_nb[50] ={0};

  for(int i = 0;i < N;++i){
    for(int j = 0;j < M;++j){
      cin>>mass;
      if(mass == 'W'){
        frag_nr[i] += 1;
        frag_nb[i] += 1;
      }
      else if(mass == 'R'){
        frag_nw[i] += 1;
        frag_nb[i] += 1;
      }
      else{
        frag_nw[i] += 1;
        frag_nr[i] += 1;
      }
    }
    //cout<<frag_nw[i]<<" "<< frag_nr[i]<<" "<< frag_nb[i]<<endl;
  } 

  int sum = 2600;
  int sum_n = 0;

  int sum_w = 0;
  for(int i = 0;i < N - 2;++i){
    sum_w += frag_nw[i];

    int sum_b = 0;
    for(int j = i + 1;j < N - 1;++j){
      sum_b += frag_nb[j];

      int sum_r = 0;
      for(int k = j + 1;k < N;++k){
        sum_r += frag_nr[k];
      }

      sum_n = sum_w + sum_r + sum_b;
      //cout<<sum_w<<" "<<sum_b<<" "<<sum_r<<endl;
      //cout<<sum_n<<endl;
      sum = min(sum,sum_n);
    }
  }
  //cout<<endl;
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 3088
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := iScan(), iScan()
	s := Scan()
	x := make([]int, 1, n)
	x[0] = 1
	c := 0
	for i := 1; i < n; i++ {
		if s[i-1] != s[i] && c == k*2 {
			x = append(x, 1)
		} else {
			if s[i-1] != s[i] {
				c++
			}
			x[len(x)-1]++
		}
	}
	fmt.Println(sum(x) - len(x))
}


Measured memory_bytes: 2804
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, W, w[101], v[101];
int dp[101][201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> W;
    rep(i, 0, N) cin >> w[i] >> v[i];

    rep(i, 0, N + 1) rep(val, 0, N * 1010 + 1) dp[i][val] = inf;
    dp[0][0] = 0;

    rep(i, 0, N) rep(val, 0, N * 1010 + 1) {
        chmin(dp[i + 1][val], dp[i][val]);
        chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]);
    }

    int ans = 0;
    rep(val, 0, N * 1010 + 1) if (dp[N][val] <= W) chmax(ans, val);
    cout << ans << endl;
}


Measured memory_bytes: 77952
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll n,l;
cin>>n>>l;
vep a;
f(i,0,n)
{
    a.pb(mp(abs(l+i),l+i));
}
sort(all(a));
ll s=0;
f(i,1,sz(a))
s+=a[i].se;
c(s);
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


Measured memory_bytes: 256
//Exp val.
//https://atcoder.jp/contests/dp/tasks/dp_j
//https://codeforces.com/blog/entry/64250?#comment-523543
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int n;
int dp[3000][3000];
int v[3000];

int f(int i,int j){
    if(i==j)return v[i];
    int &ans=dp[i][j];
    if(ans!=-1)return ans;
    
    ans=max(v[i]-f(i+1,j),v[j]-f(i,j-1));
    
    return ans;
    
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    cout<<f(0,n-1);
}


Measured memory_bytes: 70784
S = input()
S = list(S)
N = len(S)


if S == list(reversed(S)):
  a = []
  b = []
  for i in range(int((N - 1) / 2)):
    a.append(S[i])
  for i in range(int((N + 3) / 2 - 1), N):
    b.append(S[i])

  if (a == list(reversed(a))) and (b == list(reversed(b))):
    print("Yes")
  else:
    print("No")
else:
  print("No")


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
def powl(x, n, l):#繰り返し2乗法 O(log n)
    ans = 1
    while n > 0:
        if bin(n & 1) == bin(1):
            ans = ans*x
        x = (x*x)%l
        n = n >> 1 #ビットシフト
    return ans

n,a,b=map(int,input().split())

out=powl(2,n,pow(10,9)+7)-1
X,Y=1,1
for i in range(a):
    X=(X*(i+1))%(pow(10,9)+7)
    Y=(Y*(n-i))%(pow(10,9)+7)
out-=Y*powl(X,pow(10,9)+5,pow(10,9)+7)

for i in range(a,b):
    X=(X*(i+1))%(pow(10,9)+7)
    Y=(Y*(n-i))%(pow(10,9)+7)
out-=Y*powl(X,pow(10,9)+5,pow(10,9)+7)

print(out%(pow(10,9)+7))

Measured memory_bytes: 39152
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	int *x;
	int min_x,max_x;
	int *sum;
	cin >> n;
	x = new int [n];
	for(int i = 0;i <= n-1;i++){
		cin >> x[i];
	}
	sort(x,x + n);
	max_x = x[n-1];
	min_x = x[0];
	sum = new int[max_x - min_x + 1];
	for(int i = min_x;i <= max_x;i++){
		sum[i - min_x] = 0;
		for(int j = 0;j <= n-1;j++){
			sum[i - min_x] += (x[j] - i) * (x[j] -i);
		}
	}
	sort(sum,sum + max_x - min_x + 1);
	cout << sum[0];
	return 0;
}


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

int main(void) {
    i64 a, b;
    cin >> a >> b;
    if (a >= 13) cout << b << endl;
    if (6 <= a && a <= 12) cout << b / 2 << endl;
    if (a <= 5) cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;
const long long inf = (int) 1e18;
const int N = 3005;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  char mat[n + 5][m + 5];
  for (int i = 1; i <= n; i++) {
    scanf("%s", mat[i] + 1);
  }
  long long dp[n + 5][m + 5];
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) {
        dp[i][j] = 1;
        continue;
      }
      if (mat[i][j] != '.') {
        dp[i][j] = 0;
      } else {
        if (i > 1) {
          dp[i][j] += dp[i - 1][j];
          dp[i][j] %= mod;
        }
        if (j > 1) {
          dp[i][j] += dp[i][j - 1];
          dp[i][j] %= mod;
        }
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;
}

Measured memory_bytes: 256
function main(input):void {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inpt: Array<string> = input.split('\n');

	const list = inpt[0].split(' ');

	const num1: number = +list[1] - +list[0];
	const num2: number = +list[2] - +list[1];

	console.log((num1 === num2) ? 'YES' : 'NO');
}

// *** debug start ***
function debug(): void{
	const input = (<HTMLInputElement>document.getElementById('input')).value;
	input && main(input);
}
// *** debug end ***

//
declare function require(x: string): any;
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
    try(Scanner sc= new Scanner(System.in)){
    String line = sc.nextLine();
    String answer = "";
    int length = line.length();
    for(int i=0;i<length;i++){
        char ch = line.charAt(i);
        if(Character.isLowerCase(ch)) {
            ch = Character.toUpperCase(ch);
        }
        else{
            ch = Character.toLowerCase(ch);
        }
        answer = answer+ch;

    }
        System.out.println(answer);
    }
    }
}



Measured memory_bytes: 31160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
const ll mod=1000000007;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yes(T b){if(b)out("yes");else out("no");}
template<class T> void Yes(T b){if(b)out("Yes");else out("No");}
template<class T> void YES(T b){if(b)out("YES");else out("NO");}
template<class T> void no(T b){if(b)out("no");else out("yes");}
template<class T> void No(T b){if(b)out("No");else out("Yes");}
template<class T> void NO(T b){if(b)out("NO");else out("YES");}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
 


int main(){
    char a;
    cin>>a;
    if(a>='A'&&a<='Z'){
        cout<<"A"<<endl;
    }else{
        cout<<"a"<<endl;
    }
    
    
}


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

const int N = 1e5 + 5;

int n, m, x, y, fa[N], S[N], du[N], S2[N];
vector <int> G[N];

int trans(int now, int bef) {
	if(G[now][0] == bef) return G[now][1];
	return G[now][0];
}

bool check() {
	vector <int> g6, g4;
	g6.clear(), g4.clear();
	for(int i = 1; i <= n; ++ i) {
		if(du[i] & 1) return 0;
		if(du[i] >= 4) g4.push_back(i);
		if(du[i] >= 6) g6.push_back(i);
	}
	if(g6.size()) return 1;
	if(g4.size() >= 3) return 1;
	if(g4.size() == 2) {
		int now = g4[0], tot = 0;
		for(int i = 0; i < (int) G[now].size(); ++ i) {
			int cur = G[now][i], bef = now;
			while(du[cur] == 2) {
				int tmp = trans(cur, bef);
				bef = cur;
				cur = tmp;
			}
			tot += (cur == g4[1]);
		}
		return tot == 2;
	}
	return 0;
}

int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; ++ i) fa[i] = i, S2[i] = 1;
	for(int i = 1; i <= m; ++ i) {
		scanf("%d%d", &x, &y);
		++ du[x], ++ du[y];
		G[x].push_back(y);
		G[y].push_back(x);
	}
	puts(check() ? "Yes" : "No");
}

Measured memory_bytes: 6912
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 2e5+10;
int a[maxn];
int n;
int dp[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		dp[a[i]]=dp[a[i]-1]+1;
	int ans=0;
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%d",n-ans);
	return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
#define INF (ll)1e18

#define SIZE 210
ll n, W; 
ll best_feasible = -INF;
vector<P> ab;
vll v, w;

// [0, i)がb[0, i)のように確定していて、その後が不確定である時、線形緩和問題を解く
// 返り値(double, bool) = (緩和問題の最適解, その最適解が元問題の制約を厳密に満たすか)
pair<double, bool> solveRelaxationProblem(ll i, bitset<SIZE>& b) {
    double ans = 0;
    double w_now = W;
    rep(j, i) ans += b[j] * v[j], w_now -= b[j] * w[j];
    bool faf = 1;
    repi(j, i, n) {
        double tmp = min<double>(w_now, w[j]);
        faf &= (tmp == 0 || tmp == w[j]);
        w_now -= tmp;
        ans += tmp * (v[j] * 1.0 / w[j]);
    }
    return make_pair(ans, faf);

}

// [0, i)がb[0, i)のように確定していてその後が不確定である時、線形緩和問題を解く
// （負荷情報として、確定しているところの価値総和がv_now, 重さ総和w_nowを持っておく）
//
// 返り値double = 最適解
ll dfs(ll i, bitset<SIZE>& b, ll v_now, ll w_now) {
//    string s = b.to_string(); reverse(begin(s), end(s)); cout << s << endl;
    if (i == n) { best_feasible = max<ll>(best_feasible, v_now); return v_now; }

    auto relax_p = solveRelaxationProblem(i, b);
    double relax = relax_p.first; 
    double satisfiability = relax_p.second;

    if (satisfiability) { best_feasible = max<ll>(best_feasible, relax); return relax; } // 緩和問題の解を与える選び方が元問題の制約を満たしているので、それが最適でもある
    if (relax < best_feasible) { return -INF; } // 緩和問題の解が、今までの最善許容解に達さないので、探索しても無駄

    ll tmp = -INF;

    // 解がありそうな方を先に分岐するのが極めて重要！今回、0->1の順番で分岐するとTLEする。
    // 1を分岐
    if (w_now+w[i]<=W) {
        b[i] = 1;
        chmax(tmp, dfs(i+1, b, v_now+v[i], w_now+w[i]));
        b[i] = 0;
        chmax(best_feasible, tmp);
    }
    // 0を分岐
    chmax(tmp, dfs(i+1, b, v_now, w_now));
    chmax(best_feasible, tmp);

    return tmp;
}
int main(void) {
    cin >> n >> W;
    ab.resize(n); rep(i, n) cin >> ab[i].second >> ab[i].first;
    sort(ab.begin(), ab.end(), [&](P l, P r) { return l.first*r.second>r.first*l.second; });
    v = vll(n), w = vll(n);
    rep(i, n) {
        v[i] = ab[i].first;
        w[i] = ab[i].second;
    }
    
    bitset<SIZE> b;
    cout << dfs(0, b, 0, 0) << endl;;

    return 0;
}



Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-15 07:28:55
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int my_pow(int n, int k) {
  int ret = 1;
  for (int i = 0; i < k; ++i) ret *= n;
  return ret;
}

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

  int x; cin >> x;

  vector<int> beki;
  beki.emplace_back(1);

  for (int i = 2; i * i <= 1000; ++i) {
    int p = 2;
    while (my_pow(i, p) <= 1000) {
      beki.emplace_back(my_pow(i, p));
      ++p;
    }
  }

  sort(all(beki));

  auto pos = upper_bound(all(beki), x);

  cout << *(pos - 1) << endl;

  return 0;
}

Measured memory_bytes: 256
import math
A,B,H,M=map(int,input().split())
D=abs((H/12+M/(60*12)-M/60)*360)
if D==0:
    l=abs(A-B)
    print(l)
else:
    d=math.cos(math.radians(D))
    X=A**2+B**2-2*A*B*d
    x=math.sqrt(X)
    print(x)


Measured memory_bytes: 9444
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

int n,m;
int x[512][512];
int p[512],q[512];
bool t[512];

int main(){
	scanf("%d%d",&n,&m);
	fore(i,0,n)fore(j,0,m)scanf("%d",&x[i][j]),x[i][j]--;
	int r=n;
	fore(i,0,m){
		memset(q,0,sizeof(q));
		fore(j,0,n){
			while(t[x[j][p[j]]])p[j]++;
			q[x[j][p[j]]]++;
		}
		int k=max_element(q,q+m)-q;
		r=min(r,q[k]);
		t[k]=true;
	}
	printf("%d\n",r);
	return 0;
}

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

#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1000000007;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  string s = stin();
  int n = SZ(s);
  bool ok = s[n-1] == '0' && s[0] == '1';
  REP(i, n-1){
    if(s[i] == '1' && s[n-2-i] != '1'){
      ok = false;
    }
  }
  if(!ok){
    puts("-1");
    return 0;
  }
  int cur = 1;
  FOR(i, 1, n){
    if(s[i] == '1'){
      while(cur != i + 1){
        printf("%lld %d\n", i+1, cur);
        cur++;
      }
    }
  }
  printf("%d %d\n", n, n-1);
  
  return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int p[25] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
    int m;
    int i, j;
    int a[25] = {};
    for (i = 0; i < 25; i++)
    {
        m = n;
        j = p[i];
        while (m / j > 0)
        {
            a[i] += m / j;
            j *= p[i];
        }
    }
    int x, y;
    x = y = 0;
    for (i = 0; i < 25; i++)
    {
        if (a[i] >= 4)x++;
        if (a[i] >= 2)y++;
    }
    int ans = 0;
    ans += x * (x - 1)*(y - 2) / 2;
    x = y = 0;
    for (i = 0; i < 25; i++)
    {
        if (a[i] >= 24)x++;
        if (a[i] >= 2)y++;
    }
    ans += x * (y - 1);
    x = y = 0;
    for (i = 0; i < 25; i++)
    {
        if (a[i] >= 14)x++;
        if (a[i] >= 4)y++;
    }
    ans += x * (y - 1);
    x = 0;
    for (i = 0; i < 25; i++)
        if (a[i] >= 74)x++;
    ans += x;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=222222;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
template<typename T>
inline void read(T &x){
	x=0;
	char ch=getchar();bool f=false;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	if(f) x=-x;
}
int n,cnt;
ll ans,x,d;
vector<pair<ll,ll> > v[maxn];
map<ll,int> id;
int main(){
	read(n);read(x);read(d);
	if(d==0){
		if(x==0) puts("1");
		else printf("%d\n",n+1);
		return 0;
	}
	if(d<0) x=-x,d=-d;
	FOR(i,0,n){
		ll l=1ll*i*(i-1)/2,r=1ll*(2*n-i-1)*i/2;
		ll xx=1ll*x*i;
//		printf("%lld [%lld,%lld]\n",xx,l,r);
		l+=xx/d,r+=xx/d;
		xx%=d;
		if (xx<0) xx+=d,--l,--r;
		if(!id[xx]) id[xx]=++cnt;
//		printf("%lld [%lld,%lld]\n",xx,l,r);
		v[id[xx]].push_back(make_pair(l,r));
	}
	FOR(i,1,cnt){
		if(v[i].empty()) continue;
		sort(v[i].begin(),v[i].end());
		ll mxr=-1e18;
		FOR(j,0,(int)v[i].size()-1){
			ans+=max(0ll,v[i][j].second-max(v[i][j].first-1,mxr));
			mxr=max(mxr,v[i][j].second);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	int cnt = 0;
	vi d1s(N), d2s(N);
	REP(i,N) cin >> d1s[i] >> d2s[i];
	REP(i,N) {
		if (d1s[i] == d2s[i]) {
			++cnt;
			if (cnt == 3) {
				cout << "Yes" << endl;
				return;
			}
		} else {
			cnt = 0;
		}
	}
	cout << "No" << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] x = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(x[0]);
            int i = Convert.ToInt32(x[1]);

            Console.WriteLine(n - i + 1);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 27388
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

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

	std::vector<int> xs(n);
	for (auto&& e : xs)
		std::cin >> e;

	int m = std::round(std::accumulate(xs.begin(), xs.end(), 0) * 1.0 / n);
	int ans = 0;
	for (auto&& e : xs)
		ans += (e - m) * (e - m);

	std::cout << ans << std::endl;
}

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

int n;
long long ans;
vector<int> a, b, c;
vector<long long> f;

int main()
{
	int i, x;
	cin >> n;
	f.resize(n+1);
	
	for (i=0; i<n; ++i)
	{
		cin >> x;
		a.push_back(x);
	}
	
	for (i=0; i<n; ++i)
	{
		cin >> x;
		b.push_back(x);
	}
	
	for (i=0; i<n; ++i)
	{
		cin >> x;
		c.push_back(x);
	}
	
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	
	for (i=0; i<n; ++i)
	{
		if (b[i]>=c.back()) break;
		f[i+1]=(long long)n-(distance(c.begin(), \
			upper_bound(c.begin(), c.end(), b[i])));
	}
	
	f[0]=0;
	
	for (i=0; i<n; i++)
	{
		f[i+1]+=f[i];
	}
	
	for (i=0; i<n; ++i)
	{
		if (a[i]>=b.back()) break;
		ans+=f[n]-f[distance(b.begin(), \
			upper_bound(b.begin(), b.end(), a[i]))];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2552
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int res = 0;
    FOR(i, 1, N + 1, 1) {
        int s = 0, r = i;
        while (r != 0) {
            s += r % 10;
            r /= 10;
        }
        if (s >= A && s <= B) {
            res += i;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        long n = scanner.nextLong();
        long k = scanner.nextLong();

        long div = n % k;
        long result = Math.abs(div - k);
        System.out.println(Math.min(result, div));
    }
}


Measured memory_bytes: 25428
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
    s = inputStrOnebyOne()
    s[3] = 8
    print(''.join(map(str,(s))))

if __name__=='__main__':
    main()

Measured memory_bytes: 3316
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String word = sc.next();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int num[] = new int[w];
        for(int i=0;i<w;i++){
            num[i] = i+1;
        }
        //String a[] = new String[2];
        String tmp;
        int tmpNum;
        for(int i=0;i<n;i++){
            tmp = sc.next();
            String a[] = tmp.split(",",0);
            //System.out.println(a[0]);
            tmpNum = num[Integer.parseInt(a[0])-1];
            num[Integer.parseInt(a[0])-1] = num[Integer.parseInt(a[1])-1];
            num[Integer.parseInt(a[1])-1] = tmpNum;
        }
        for(int i=0;i<w;i++){
            System.out.println(num[i]);
        }
        sc.close();
    }
}


Measured memory_bytes: 26320
#include<bits/stdc++.h>
#define int long long
using namespace std;
const double eps=1e-8;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
bool eq(double x,double y)
{
	return fabs(x-y)<eps;
}

signed main()
{
	int n=read(),ans=0;
	for (int l=1,r;l<=n;l=r+1)
	{
		int k=n/l;
		r=n/k;
		if (l<=n/k-1&&n/k-1<=r&&eq(n/k,double(n)/double(k))) ans+=n/k-1;
	}
	print(ans);

	return 0;
}

Measured memory_bytes: 3616
# ITP1_11_B: Dice2

class Dice
  module Pip
    TOP    = 0
    FRONT  = 1
    RIGHT  = 2
    LEFT   = 3
    BACK   = 4
    BOTTOM = 5
  end

  def initialize(labels)
    @labels = labels
  end
 
  def top
    @labels[Pip::TOP]
  end

  def front
    @labels[Pip::FRONT]
  end

  def right
    @labels[Pip::RIGHT]
  end
 
  def rotate(p1, p2, p3, p4)
    src = @labels[p4], @labels[p1], @labels[p2], @labels[p3]
    @labels[p1], @labels[p2], @labels[p3], @labels[p4] = src
  end
 
  def roll_to(direction)
    rotate *case direction
    when 'N'
      [Pip::TOP, Pip::FRONT, Pip::BOTTOM, Pip::BACK]
    when 'E'
      [Pip::TOP, Pip::LEFT, Pip::BOTTOM, Pip::RIGHT]
    when 'S'
      [Pip::TOP, Pip::BACK, Pip::BOTTOM, Pip::FRONT]
    when 'W'
      [Pip::TOP, Pip::RIGHT, Pip::BOTTOM, Pip::LEFT]
    end
  end
end
 
labels     = gets.split.map &:to_i
n_changes  = gets.to_i
directions = %w(N E S W)
dice       = Dice.new labels

n_changes.times do
  top, front = gets.split.map &:to_i
  while true
    dice.roll_to directions.sample
    if dice.top == top && dice.front == front
      puts dice.right
      break
    end
  end
end

Measured memory_bytes: 8680
#include <iostream>
#include <cstdio>

#include <algorithm>
#include <cmath>
#include <functional>

#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <list>

#define ll long long int

using namespace std;

int main(int argc, char const* argv[]) {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i != n; ++i) {
        cin >> h[i];
    }

    int max_h = 0;
    int ans = 0;

    for (int i = 0; i != n; ++i) {
        if (h[i] >= max_h) {
            max_h = h[i];
            ans += 1;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
square = 0

if b <= 9:
    square = a * 10 + b
elif b <= 99:
    square = a * 100 + b
else:
    square = a * 1000 + b

#squareの平方数判定
for i in range(1,1002):
    if i ** 2 == square:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();

    set<string> st;

    rep(i, n) {
        for(int j = 1; j <= k; j++) {
            if(i+j-1 < n) {
                string t = s.substr(i, j);
                st.insert(t);
            }
        }
    }

    /*cout << "\n";
    for(auto pos = st.begin(); pos != st.end(); pos++) {
        cout << *pos << "\n";
    }*/

    auto pos = st.begin();
    rep(i, k-1) {
        pos++;
    }

    cout << *pos << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
	int N, A, B;
	
	cin >> N >> A >> B;
	
	int ans = 0;
	
	for (int i = 1; i <= N; i++) {
		int tmp = i;
		int sum = 0;
		
		while (tmp != 0) {
			sum = sum + (tmp % 10);
			tmp /= 10;
		}
		
		if (A <= sum && sum <= B) {
			ans += i;
		}
	}
	
	cout << ans << endl;
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  long long n, cnt = 2;
  cin >> n; 

  if (n == 2) cnt--;
  long long nn = n-1;
  for (long long i = 2; i <= sqrt(nn); ++i) {
    if (nn % i)  continue;
    if (i * i != nn) cnt += 2;
    else cnt += 1;
  }

  auto reduce = [](long long val, long long x) {
    while (val >= x) {
      if (val % x == 0) val /= x;
      else val %= x;
    }
    return val;
  };

  for (long long i = 2; i <= sqrt(n); ++i) {
    if (n % i)  continue;
    if (reduce(n, i) == 1)  cnt++;
    if (i * i != n && reduce(n, n/i) == 1)  cnt++;
  } 

  cout << cnt << endl;
}


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

int main(){
    int n; //頂点の数
    int x; //辺を結ぶ頂点の番号
    int y; //辺を結ぶ頂点の番号
    cin >> n >> x >> y;

    vector<int> k(n); //要素数が最短距離で、要素がその数
    /* 頂点i,jを固定して最短距離を求め、数える */
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            k[min(j-i,abs(i-x)+1+abs(j-y))] += 1;
        }
    }

    for(int i=1; i<=n-1; i++) cout << k[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll h(n);
    rep(i, n){
        cin >> h[i];
    }
    ll inith = h[0];
    ll ans = 0;
    ll ansm = 0;
    repr(i, 1, n){
        if(h[i] <= h[i-1]){
            ans++;
            chmax(ansm, ans);
        }else{
            ans = 0;
        }
    }
    cout << ansm << endl;
    return 0;
}

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

using namespace std;

int64_t a[100'000];
int64_t gain[100'000];

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

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

    int64_t bottom = 1'000'000'000;
    int64_t maxGain = 0;
    for (int i = 0; i < N; i++)
    {
        bottom = min(bottom, a[i]);
        gain[i] = a[i] - bottom;

        maxGain = max(maxGain, gain[i]);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (gain[i] == maxGain)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
char map[101][101];
int vis[101][101];
int ans;
int H, W;
void dfs(int x, int y,char c)
{
	if (c != map[x][y])
		return;
	if (vis[x][y])
		return;
	vis[x][y] = 1;
	if (x > 0) dfs(x - 1, y, map[x][y]);
	if (x < H - 1) dfs(x + 1, y, map[x][y]);
	if (y > 0) dfs(x, y - 1, map[x][y]);
	if (y < W - 1) dfs(x, y + 1, map[x][y]);
}
int main()
{
	while (cin >> H >> W&&H&&W)
	{
		ans = 0;
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
			{
				cin >> map[i][j];
				vis[i][j] = 0;
			}
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				if (!vis[i][j])
				{
					dfs(i, j, map[i][j]);
					ans++;
				}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python3
#EDPC I

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(float,sys.stdin.readline().split()))

n = I()
P = LI()
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    p = P[i-1]
    for j in range(n+1):
        if j > 0:
            dp[i][j] = (1-p)*dp[i-1][j] + p*dp[i-1][j-1]
        else:
            dp[i][j] = (1-p)*dp[i-1][j]
print(sum(dp[-1][n//2+1:]))
        


Measured memory_bytes: 259464
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define module 1000000007
#define pb push_back
#define IOS ios_base::sync_with_stdio(fals00e); cin.tie(NULL);
 
#define vi vector<int>
#define vll vector<long long>

#define MAX 100001

int main()
{
	string s,t;
	ll i,counter=0;
	cin>>s>>t;
	counter=0;
	for(i=0;i<=2;i++)
	{
		if(s[i]==t[i])
			counter++;
	}
	cout<<counter<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		for(int i=0; i<4; i++){
			int n1 = n % 10;
			if(n1 == 2){
				ans++;
			}
			n = (n-n1)/10;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
#include <cstdio>

using namespace std;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int res=0;
    for (int i=a; i<=b; ++i)
        if (c%i == 0)
            ++res;

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 2752
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 200005
const int INF=1000000;
int n,m,w[maxn],pre[maxn],other[maxn],last[maxn],o,l[maxn],r[maxn];
bool flag[maxn];

void connect(int x,int y)
{
    o++;
    pre[o]=last[x];
    last[x]=o;
    other[o]=y;
}

void dfs(int u,int fa)
{
    l[u]=-INF;r[u]=INF;
    if (flag[u]) l[u]=r[u]=w[u];
    for (int p=last[u];p;p=pre[p]) 
    {
        int v=other[p];
        if (v==fa) continue;
        dfs(v,u);
        l[u]=max(l[u],l[v]-1);
        r[u]=min(r[u],r[v]+1);
    }
    if (l[u]>r[u]) {puts("No");exit(0);}
}

void solve(int u,int fa)
{
    if (u==1) w[u]=l[u];
    else if (w[fa]+1>=l[u]&&w[fa]+1<=r[u]) w[u]=w[fa]+1;
    else if (w[fa]-1>=l[u]&&w[fa]-1<=r[u]) w[u]=w[fa]-1;
    else {puts("No");exit(0);}
    for (int p=last[u];p;p=pre[p]) 
    {
        int v=other[p];
        if (v==fa) continue;
        solve(v,u);    
    }
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++) 
    {
        int x,y;
        scanf("%d%d",&x,&y);
        connect(x,y);
        connect(y,x);
    }
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        w[x]=y;
        flag[x]=1;       
    }
    dfs(1,-1);
    //for (int i=1;i<=n;i++) printf("--%d %d %d--\n",i,l[i],r[i]);
    solve(1,-1);
    puts("Yes");
    for (int i=1;i<=n;i++) printf("%d\n",w[i]);
    return 0;
}

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

class UF {
  vector<int> ps;
public:
  void init(int n) {
    ps.resize(n);
    for (int i = 0; i < n; ++i) {
      ps[i] = i;
    }
  }
  int root(int i) {
    if (ps[i] == i) return i;
    return ps[i] = root(ps[i]);
  }
  bool same(int i, int j) {
    return root(i) == root(j);
  }
  void unite(int i, int j) {
    if (i == j) return;
    int ri = root(i);
    int rj = root(j);
    ps[ri] = rj;
  }
};

int n, h;
int deg[403];
bool iso[403];
UF uf;
bool sub() {
  for (int i = 0; i < 2 * h; ++i) {
    if (i < h && deg[i] < 0) return false;
    if (i >= h && deg[i] > 0) return false;
  }
  
  vector<vector<int>> gs(2 * h);
  for (int i = 0; i < 2 * h; ++i) {
    gs[uf.root(i)].push_back(i);
  }
  
  for (auto&& g : gs) {
    if (g.empty() || iso[g[0]]) continue;
    int sum = 0;
    bool ok = false;
    for (int i : g) {
      sum += deg[i];
      if (deg[i] != 0) ok = true;
    }
    if (!ok || sum != 0) return false;
  }
  return true;
}

int main() {
  cin >> n >> h;
  ++h;
  uf.init(2 * h);
  
  for (int i = 0; i < 2 * h; ++i) {
    iso[i] = true;
  }
  
  for (int i = 0; i < n; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int x = c == 0 ? a : c + h;
    int y = d == 0 ? b + h : d;
    ++deg[x];
    --deg[y];
    iso[x] = false;
    iso[y] = false;
    uf.unite(x, y);
  }
  
  cout << (sub() ? "YES" : "NO") << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n;
    cin >> n;

    vs64 a(n);
    rep (i, n) cin >> a[i];

    s64 ans = 0;
    int r = 0;
    s64 x = 0;
    s64 s = 0;
    for (int l = 0; l < n; ++l)
    {
        while (r < n && (x ^ a[r]) == (s + a[r]))
        {
            x ^= a[r];
            s += a[r];
            ++r;
        }
        ans += r - l;
        if (r < l + 1) ++r;
        x ^= a[l];
        s -= a[l];
    }

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



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

int main(){
  
  int n;
  cin>>n;
  int h[n];
  for(int i=0; i<n; i++) cin >>h[i];
  
  int a=h[0];
  bool flg=0;
  for(int i=1; i<n; i++){
  	if(a>h[i]){ if(a-h[i]==1) continue;
    			else flg=1; break;
              }
    else a=h[i];
  }

  if(flg) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define N 10000

int main()
{
  int n, a[N], i, j, judge, count=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }

  for(i=0; i<n; i++){
    judge = 0;
    if(a[i] == 2) judge = 0;

    else if(a[i] < 2 || a[i]%2 == 0) judge = 1;
    
    j = 3;
    while(j <= sqrt(a[i])){
      if(a[i]%j == 0){
	judge = 1;
	break;
      }
      j = j+2;
    }

    if(judge == 0) count++;
  }
  
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 1772