akhauriyash/Code-Regression huggingface dataset:
// ITP1_7_C
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}

Measured memory_bytes: 25428
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9+7

ans = 0
for i in range(N):
    left = 0
    right = 0
    for j in range(N):
        if(i > j and A[i] > A[j]):
            left += 1
        if(j > i and A[i] > A[j]):
            right += 1
    ans += right*((K+1)*K)//2+(left*(K*(K-1)))//2
print(ans%mod)

Measured memory_bytes: 3188
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<int,int>;

int main(){

  int N, M, L, R;
  cin >> N >> M;
  int ans = 0;

  int l = 0, r = 1e9;
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    l = max(l,L);
    r = min(r,R);
  }
  // cout << l << endl;
  // cout << r << endl;

  if(l>r){
    cout << 0 << endl;
  }else{
    cout << r-l+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3596
use std::rc::Rc;

pub fn main() {
  fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse::<T>().ok().unwrap()
  }
  fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
  }

  let n = read::<String>();
  let ans:u32 = n.chars().fold(0, |a, b| a + b.to_digit(10).unwrap()) % 9;
  println!("{}", if ans == 0 {"Yes"} else {"No"});

}


Measured memory_bytes: 2284
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll n,k;
  cin >> n >> k;
  vector<lll> a,a2,num,num2;
  const lll mod = 1000000007;
  a.resize(n);
  a2.resize(n*2);

  num.resize(n);
  num2.resize(n);
  
  for(ii=0;ii<n;ii++){
    cin >> a[ii];
  }
  
  for(ii=0;ii<n*2;ii++){
    a2[ii] = a[ii%n];
  }
  lll ans1,ans2;
  ans1 = 0;
  ans2 = 0;
  for(ii=0;ii<n-1;ii++){
    for(jj=ii+1;jj<n;jj++){
      if(a[ii] > a[jj]){
        ans1++;
      }
    }
  }

  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      if(a2[ii] > a2[jj]){
        ans2++;
      }
    }
  }

  //for(ii=0;ii<n;ii++){
  //  cout << "num:" << num[ii] << "num2:" << num2[ii] << endl;
  //}
  lll sum = 0;

  lll tmp;
//  for(ii=0;ii<n;ii++){
//    sum += (num[ii] * k) % mod;
//  }
  
//  for(ii=0;ii<n;ii++){
//    tmp = (num2[ii] * (k*(k-1)/2)) % mod;
//    //cout << "tmp:" << tmp << endl;
//    sum = (sum + tmp) %  mod;
//    //cout << "sum:" << sum << endl;
//  }

  //for(ii=0;ii<n;ii++){
  //  sum += num2[ii];
  //}
  
  //cout << ans1*k + (k*(k-1)/2%mod*ans2)%mod << endl;
  cout << ((ans1*k) + (((k*(k-1)/2%mod*ans2))))%mod << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

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

    vector<bool> is_prime(5*55555+1, true);
    is_prime[1] = false;
    for(int i=2; i<=5*55555; i++){
        for(int j=i+i; j<=5*55555; j+=i){
            is_prime[j] = false;
        }
    }
    vector<int> primes;
    for(int i=2; i<=5*55555; i++){
        if(is_prime[i] && i<=55555) primes.push_back(i);
    }

    vector<int> res;
    int last = 0;
    for(int i=0; i<N; i++){
        for(; last<=primes.size(); last++){
            if(primes[last]%5==1){
                cout << primes[last];
                if(i==N-1) cout << endl;
                else cout << " ";
                last++;
                break;
            }
        }
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		if(Y % 2 != 0) {
			prtln("No");
			return;
		}
		if(X * 4 == Y) {
			prtln("Yes");
			return;
		}
		if(X * 2 == Y) {
			prtln("Yes");
			return;
		}
		boolean ok = false;
		for(int i = 1; i <= X; i++) {
			// System.out.println((Y - (i * 4)) / 2 +" == "+ (X - i));
			if((Y - (i * 4)) / 2 == (X - i)) {
				ok = true;
				break;
			}
		}
		prtln(ok ? "Yes" : "No");
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


Measured memory_bytes: 26996
def main():
    n = int(input())

    adjacency_matrix = []
    for _ in range(n):
        u, k, *V = map(int, input().split())
        col = [0] * n
        for v in V:
            col[v-1] = 1
        adjacency_matrix.append(col)
    for col in adjacency_matrix:
        print(*col)


if __name__ == "__main__":
    main()



Measured memory_bytes: 6380
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}


macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: [usize; 3],
    }

    let mut y = x.clone();
    y.sort();
    y.dedup();
    y.len().to_string()
}

Measured memory_bytes: 4352
def resolve():
  s = input()
  ans = ""

  for i in range(1, len(s) // 2):
    a = s[0:i]
    b = s[i:2*i]
    if a == b:
      ans = len(a) + len(b)

  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){
    int S;
    int h, m, s;
    cin >> S;
    h = S/3600;
    S = S%3600; 
    m = S/60;
    s = S%60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
using namespace std;
int main(){
	int ans,b;
	char z;
	cin>>ans;
	while(true){
		cin>>z;
		if(z=='=')
			break;
		cin>>b;
		if(z=='+')
			ans+=b;
		if(z=='-')
			ans-=b;
		if(z=='*')
			ans*=b;
		if(z=='/')
			ans/=b;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1160
import collections

h,w = map(int,input().split())
sy,sx = map(int,input().split())
gy,gx = map(int,input().split())
maze = [list(input()) for i in range(h)]

sy -= 1
sx -= 1
gy -= 1
gx -= 1

field = [[False for i in range(w)] for j in range(h)]
field[sy][sx] = True
dx = [1,0,-1,0]
dy = [0,1,0,-1]

q = collections.deque()
q2 = collections.deque()
q.append((sy,sx))
count = 0
maze[sy][sx] = 0

def f(count):
    while q:
        s = q.popleft()
        y,x = s[0],s[1]
        count = maze[y][x]
        for i in range(4):
            newy = y + dy[i]
            newx = x + dx[i]
            if 0<=newy<h and 0<=newx<w:
                if newy == gy and newx == gx:
                    print(count)
                    exit()
                if maze[newy][newx] == ".":
                    maze[newy][newx] = count
                    q.appendleft((newy,newx))
                elif maze[newy][newx] != "#" and field[newy][newx] == False:
                    maze[newy][newx] = count
                    q.appendleft((newy,newx))
                field[newy][newx] = True
        for ddy in range(-2,3):
            for ddx in range(-2,3):
                newy = y+ddy
                newx = x+ddx
                if  0<=newy<h and 0<=newx<w:
                    if maze[newy][newx] == "." and field[newy][newx] == False:
                        maze[newy][newx] = count+1
                        q.append((newy,newx))

f(count)
if maze[gy][gx] != ".":
    print(maze[gy][gx])
else:
    print(-1)

Measured memory_bytes: 170860
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(n,x,y):
    l = len(n)
    sm = 0
    if x==y and (l>1 or n[0]>=x):
        sm = 1
    if l==1:
        return sm
    for i in range(2,l):
        sm += 10**(i-2)
    if x==n[-1]:
        sm += bar(n[:-1],y)
    elif x<n[-1]:
        sm += 10**(l-2)
    #ddprint(f"foo {n=} {x=} {y=} {sm=}")
    return sm

def bar(n,y):
    l = len(n)
    if l==1:
        return 1 if n[0]>=y else 0
    sm = (n[-1])*10**(l-2) + bar(n[:-1],y)
    return sm

nn = inn()
nnn = nn
n = []
while nn>0:
    n.append(nn%10)
    nn //= 10
sm = 0
for a in range(1,nnn+1):
    y = a%10
    if y==0:
        continue
    aa = a
    while aa>0:
        x = aa
        aa //= 10
    sm += foo(n,y,x)
print(sm)


Measured memory_bytes: 43612
#include <bits/stdc++.h>
  #define Mod 1000000007
  #define INF 1e9
  #define INFL 9e18
  #define EPS 1e-9
  #define pb push_back
  #define mp make_pair
  #define SET(a) memset(a,-1,sizeof(a))
  #define CLR(a) memset(a,0,sizeof(a))
  #define CPY(a,b) memcpy(a,b,sizeof(a))
  #define N 500005
  #define fs first
  #define sc second
  #define UNIVISITED 0
  #define EXPLORED 1
  #define VISITED 2
  using namespace std;
  typedef  long long int ll;
  typedef pair<ll,ll> ii;
  typedef vector <ii> vii;
  typedef vector <ll> vi;

ll arr[N];

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

ll a,b;
cin>>a>>b;
if((a+b)%2==1)
  cout<<(a+b)/2+1;
else
  cout<<(a+b)/2;










  return 0;


  } 

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

using namespace std;

const int MAX_N = 100, INDEX = 1;
const int MAX_V = 10000000, INF = MAX_N * MAX_V + 1;

int N, W;
int w[MAX_N + INDEX], v[MAX_N + INDEX];
int dp[MAX_N + INDEX][MAX_N + INDEX][3 * MAX_N + INDEX];

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

    cin >> N >> W;

    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }

    dp[0][0][0] = 0;
    for (int j = 0; j <= N; j++) {
        for (int k = 0; k <= 3 * N; k++) {
            if (j > 0 || k > 0) {
                dp[0][j][k] = -INF;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= 3 * N; k++) {
                dp[i][j][k] = dp[i - 1][j][k];

                if (j > 0 && k >= w[i] - w[1]) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - (w[i] - w[1])] + v[i]);
                }
            }
        }
    }

    int ans = 0;
    for (int j = 0; j <= N; j++) {
        for (int k = 0; k <= 3 * N; k++) {
            if (j * (long long)(w[1]) + k <= W) {
                ans = max(ans, dp[N][j][k]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12288
def main():
    n = int(input())
    h = [int(i) for i in input().split()]
    ans = solve(n, h)
    print(ans)


def solve(n, h):
    dp =[0 for _ in range(n)]
    dp[1] = dp[0] + abs(h[1] - h[0])
    for i in range(1, n - 1):
        dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i - 1] + abs(h[i + 1] - h[i - 1]))
    return dp[n - 1]


if __name__ == '__main__':
    main()

Measured memory_bytes: 52720
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,res=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
	res+=i*(n-i+1);
	for(ll i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b;
		ll l=min(a,b),r=max(a,b);
		res-=l*(n-r+1);
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
	solve();
}


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

const ll mod = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, i;
    cin >> n;
    vector<ll> a(n);
    for (i=0; i<n; ++i)
        cin >> a[i];
    ll curr = 1000, ans = 1000;
    for (i=1; i<n; ++i) {
        if (a[i] > a[i-1]) {
            ans += ((a[i]-a[i-1]) * (curr/a[i-1]));
            curr = ans;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <math.h>
int main(int argc, const char *argv[]){
 int a;
 char s[11];
 scanf("%d%s",&a,s);
 if(a>=3200){
  printf("%s\n",s);
 }else{
  printf("red\n");
 }
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

void solve(){
	ll n,q;
	cin>>n;
	vector<ll> a(n,0);
	map<ll,ll> mp;
	ll s = 0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		s += a[i];
		mp[a[i]]++;
	}
	cin>>q;
	for(ll i=0;i<q;i++){
		ll x1,x2;
		cin>>x1>>x2;
		s -= x1*mp[x1];
		s += x2*mp[x1];
		mp[x2] += mp[x1];
		mp[x1] = 0;
		cout<<s<<"\n";
	}
	
}

int main(){
    fastio;
    int t;
    //cin>>t;
    t = 1;
    for(int i=1;i<=t;i++)
	solve();
	
}




Measured memory_bytes: 9932
#include<stdio.h>

int s(int a, int b) {
	int  r, tmp;

	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main(void)
{
	int a,b,c,K;
	int i, j, k;
	long long int ans = 0;
	scanf("%d", &K);
	for (i = 1; i <= K;i++) {
		for (j = 1;j <= K;j++) {
			for (k = 1;k <= K;k++) {
				ans += s(s(i,j),k);
			}
		}

	}
	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 1732
package main
import (
  "fmt"
  "sort"
)
func diff(a, b int) int {
  if a < b {
    return b - a
  }
  return a - b
}
func main() {
  var n int
  fmt.Scan(&n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i])
  }
  bs := make([]int, n)
  for i := 0; i < n; i++ {
    bs[i] = as[i]-(i+1)
  }
  sort.Ints(bs)
  mid := bs[n/2]
  result := 0
  for _, b := range bs {
    result += diff(b, mid)
  }
  fmt.Println(result)
}

Measured memory_bytes: 6656
#include <iostream>
#define mod 1000000007
#define LL long long
using namespace std;

LL N,A,B,C,D,comb[1010][1010],dp[1010][1010],fact[1010],inv[1010],ifact[1010];


int main(){
    cin >> N >> A >> B >> C >> D;

    LL i,j,k;
    for (i=0; i<=N; i++){
        comb[i][0]=1;
        for (j=1; j<=i; j++)
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
    }

    fact[0]=fact[1]=inv[1]=ifact[1]=ifact[0]=1;
    for (i=2; i<=N; i++){
        fact[i]=(i*fact[i-1])%mod;
        inv[i]=(-inv[mod%i]*(mod/i))%mod+mod;
        ifact[i]=(ifact[i-1]*inv[i])%mod;
    }

    dp[A-1][0]=1; LL cr=1,aux=1;
    for (i=A; i<=B; i++){
        aux=1;
        for (j=1; j<=C-1; j++)
            aux=(aux*ifact[i])%mod;

        for (j=0; j<=N; j++){
            dp[i][j]=dp[i-1][j];
            cr=aux;
            for (k=C; k*i<=j && k<=D; k++){
                cr=(cr*ifact[i])%mod;
                dp[i][j]=(dp[i][j]+((((((comb[j][k*i]*fact[k*i])%mod)*cr)%mod)*ifact[k])%mod)*dp[i-1][j-k*i])%mod;

            }
        }
    }

    cout << dp[B][N] << "\n";

    return 0;
}


Measured memory_bytes: 15104
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    bool P[100001];P[0]=P[1]=false;FOR(i,2,100001)P[i]=true;
    FOR(i,2,100001){
        if(P[i]){
            for(int j=i*2;j<100001;j+=i){
                P[j]=false;
            }
        }
    }
    vi Asum(100001);Asum[0]=0;
    REPS(i,100000){
        Asum[i]=Asum[i-1];
        if(P[i] and P[(i+1)/2])Asum[i]++;
    }
    ll Q;cin>>Q;
    ll l[Q],r[Q];
    REP(i,Q)cin>>l[i]>>r[i];

    REP(i,Q){
        cout<<(Asum[r[i]]-Asum[l[i]-1])<<"\n";
    }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, a;
  cin >> n >> a;
  vl x(n);
  rep(i, n) {
    cin >> x[i];
  }

  constexpr ll limit = 51;
  vector<vector<vl>> dp(n+1, vector<vl>(limit, vl(limit*limit)));
  dp[0][0][0] = 1;
  rep(i, n) {
    rep(j, limit) {
      rep(k, limit*limit) {
        dp[i+1][j][k] += dp[i][j][k];
        if (j > 0 and k-x[i] >= 0) {
          dp[i+1][j][k] += dp[i][j-1][k-x[i]];
        }
      }
    }
  }

  ll ans = 0;
  for (ll i = 1; i*a < limit*limit and i < limit; i++) {
    ans += dp[n][i][i*a];
  }
  cout << ans << endl;
}


Measured memory_bytes: 54272
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,inf=1e9;
int a[N],b[N],n;
bool cal(int md){
    for(int i=1;i<=2*n-1;i++)b[i]=a[i]>=md;
    for(int i=0;i<n-1;i++){
        if(b[n+i]==b[n+i+1])return b[n+i];
        if(b[n-i]==b[n-i-1])return b[n-i];
    }
    return b[1];
}
int main(){
    scanf("%d",&n);for(int i=1;i<=2*n-1;i++)scanf("%d",&a[i]);
    int l=1,r=2*n-1,mid,ans;
    while(l<=r){mid=l+r>>1;cal(mid)?(l=mid+1,ans=mid):r=mid-1;}
    printf("%d\n",ans);
}


Measured memory_bytes: 5368
import sys,collections,math
from operator import itemgetter
def Is(): return [int(x) for x in sys.stdin.readline().split()]

n,h = Is()
katanas = []
for i in range(n):
    katanas.append(Is())

katanas = sorted(katanas,reverse=True)
strongest = katanas[0]
katanas = sorted(katanas,reverse=True,key=itemgetter(1))
turns = 0
for katana in katanas:
    if katana[1] >= strongest[0]:
        turns += 1
        h -= katana[1]
        if h <= 0:
            print(turns)
            exit()
    else:
        break
turns += math.ceil(h/strongest[0])
print(turns)

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	cin>>N;
	vector<pair<ld, ld>>	data(N);
	FOR(i,0,N){
		ld a,b;
		cin>>a>>b;
		data.at(i) = make_pair(a,b);
	}
	ld sum=0;
	FOR(i,0,N-1){
		FOR(j,i+1,N){
			sum+=sqrtl(pow(data.at(i).first-data.at(j).first, 2.0)+pow(data.at(i).second-data.at(j).second, 2.0));
		}
	}

    cout.precision(10);
	cout<<2*sum/N<<endl;

    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  ans=inf
  for x in range(1,int(math.sqrt(n))+1):
    if n%x==0:
      ans=min(ans,x+n//x-2)
  return ans

# main()
print(main())


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

using namespace std;

using ll = long long;

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

    vector<string> a(3);
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    for (int i = 0; i < 3; ++i)
        cout << a[i][i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

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

//隣接リストを用いた場合　O(|E|log|V|)
const int MAX_V=100010;  //変える
const ll INF=10000000000000000;  //変える
struct edge {int to, cost1, cost2; }; //cost1は円
int V;

vector <edge> G[MAX_V];
ll d1[MAX_V];
ll d2[MAX_V];

void dijkstra1 (int s){
    //小さい順に取り出す firstは最短距離、secondは頂点の番号
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d1,d1+V,INF);
    d1[s]=0;
    que.push(P(0,s));
    
    while (!que.empty()) {
        P p=que.top();  que.pop();
        int v=p.second;
        if (d1[v]<p.first) continue;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (d1[e.to]>d1[v]+e.cost1){
                d1[e.to]=d1[v]+e.cost1;
                que.push(P(d1[e.to], e.to));
            }
        }
    }
}

void dijkstra2 (int s){
    //小さい順に取り出す firstは最短距離、secondは頂点の番号
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d2,d2+V,INF);
    d2[s]=0;
    que.push(P(0,s));
    
    while (!que.empty()) {
        P p=que.top();  que.pop();
        int v=p.second;
        if (d2[v]<p.first) continue;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (d2[e.to]>d2[v]+e.cost2){
                d2[e.to]=d2[v]+e.cost2;
                que.push(P(d2[e.to], e.to));
            }
        }
    }
    
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,s,t;
    cin >> V >> m >> s >> t;
    s--; t--;
    rep(i,0,m){
        int u, v, a, b;
        cin >>u>>v>>a>>b;
        u--; v--;
        G[u].push_back(edge {v,a,b}); G[v].push_back(edge {u,a,b});
    }
    dijkstra1(s);
    dijkstra2(t);
    set<P> st;
    rep(i,0,V){
        st.insert(P(d1[i]+d2[i], i));
    }
    auto a=st.begin();
    ll inf=1e15;
    rep(i,0,V){
        if (!st.empty()){
            if (i<=(*a).second){
                cout << inf-(*a).first << endl;
                st.erase(P(d1[i]+d2[i],i));
            }
            else {
                a=st.begin();
                cout << inf-(*a).first << endl;
                st.erase(P(d1[i]+d2[i],i));
            }
        }
        else break;
    }
}

Measured memory_bytes: 15996
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  xs <- replicateM n readLn :: IO [Integer]
  print $ sum $ solve xs 0

solve :: [Integer] -> Integer -> [Integer]
solve [] _ = []
solve (x:xs) u
  | u+1 >= x = solve xs $ if u+1 == x then u+1 else u
  | otherwise = (x-1)`div`(u+1) : solve xs (max 1 u)


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> v(n, -1);
    for (int i = 0; i < m; ++i) {
        int s, c;
        cin >> s >> c;
        --s;
        if (v[s] == -1 || v[s] == c) {
            v[s] = c;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (v[i] != -1) {
            if (i == 0) {
                if (n != 1 && v[i] == 0) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            continue;
        }
        if (i == 0) {
            if (n == 1) v[i] = 0;
            else v[i] = 1;
        } else {
            v[i] = 0;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = ans * 10 + v[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << "\n"; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " <<to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void solve(){
  int h,w,n;
  cin>>h>>w>>n;
  cout<<min((n+h-1)/h,(n+w-1)/w)<<"\n";
}
 
int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
OK = "O"
BRO = "B"

N,M=map(int, input().split())
Broken=[int(input()) for i in range(M)]
#K = "".join(list(BRO if i in Broken else OK for i in range(N+1)))
K = list(OK for i in range(N+1))
for i in range(M):
  K[Broken[i]] = BRO
  
if N == 1:
  print(1)
  exit()
  
c=[0 for i in range(N+1)]
if K[N-1]==OK:
  c[1]=1
if K[N-2]==OK and K[N-1]==OK:
  c[2]=2
if K[N-2]==OK and K[N-1]==BRO:
  c[2]=1

for i in range(3,N+1):
  if K[N-i]==OK:
    if K[N-i+1]==OK and K[N-i+2]==OK:
      c[i]=c[i-1]+c[i-2]
    if K[N-i+1]==OK and K[N-i+2]==BRO:
      c[i]=c[i-1]
    if K[N-i+1]==BRO and K[N-i+2]==OK:
      c[i]=c[i-2]
  c[i]%=1000000007
  
print(c[N] % 1000000007)


Measured memory_bytes: 8608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<double> v(n);
  for(int i =0; i<n; i++)
    cin>>v.at(i);
  sort(v.begin(), v.end());
  double result=v.at(0);
  for(int i=1;i<n; i++)
    result= (result + v.at(i))/2;
  
  printf("%7f\n", result);
  
  return 0;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    string s; cin >> s;

    int cnt = 0;

    rep(i,s.length()/2){
        if(s[i] != s[s.length()-i-1]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;

int N, M;

int main() {
	while (scanf("%d", &N), N) {
		vector<P> state;
		int dp[212];
		int h, r;
		rep(i, N) {
			scanf("%d %d", &h, &r);
			state.push_back(P(h, r));
		}
		scanf("%d", &M);
		rep(i, M) {
			scanf("%d %d", &h, &r);
			state.push_back(P(h, r));
		}
		sort(state.begin(), state.end());
		int res = 0;
		rep(i, state.size()) {
			dp[i] = 1;
			rep(j, i) if(state[j].first < state[i].first && state[j].second < state[i].second) {
				dp[i] = max(dp[i], dp[j] + 1);
			}
		}
		rep(i, state.size()) {
			res = max(res, dp[i]);
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 3168
// vim: ts=2 sw=2 sts=2
#include <bits/stdc++.h>
using namespace std;

int main() {
  // banpei
  int ans = 1000000000;

  // nums of input
  int n;
  cin >> n;

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

    cin >> x;
    c = 0;

    while(x % 2 == 0){
      x /= 2;
      c++;
    }

    if (c < ans)
      ans = c;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

int main() {
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X.at(i);
        Y.at(i) = X.at(i);
    }
    sort(Y.begin(), Y.end(), greater<int>());

    int ans = 1e9;
    for (int i = 1; i <= Y.at(0); i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            sum += pow(X.at(j) - i, 2);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
using ll = long long;

ll Lucas(int);

int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  cout<<Lucas(n)<<endl;
  return 0;
}

ll Lucas(int n){
  ll num1=2,num2=1,tmp=2;
  if(n==0){
    tmp=num1;
  }else if(n==1){
    tmp=num2;
  }else{
    for(int i=1;i<n;i++){
      tmp=num1+num2;
      num1=num2;
      num2=tmp;
    }
  }
  return tmp;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * A Reward for a Carpenter
 */
public class Main {

	static Main main = new Main();

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line);
			int m = Integer.parseInt(br.readLine());
			Graph graph = main.new Graph(n);

			for (int i = 0; i < m; ++i) {
				graph.addEdges(br.readLine());
			}

			StringTokenizer st = new StringTokenizer(br.readLine(), ",");
			int s = Integer.parseInt(st.nextToken());// start
			int g = Integer.parseInt(st.nextToken());// goal
			int b = Integer.parseInt(st.nextToken());// budget
			int p = Integer.parseInt(st.nextToken());// pillar

			//
			int way, back;
			way = graph.dijkstra(s, g);
			back = graph.dijkstra(g, s);

			System.out.println(b - p - way - back);

		}
	}

	class Graph {

		final int INFINITY = Integer.MAX_VALUE;
		final int UNREACHABLE = -1;

		int length;
		int[][] adjacency;

		Graph(int n) {
			length = n + 1;
			adjacency = new int[length][length];
			for (int i = 1; i < length; ++i) {
				for (int j = 1; j < length; ++j) {
					adjacency[i][j] = UNREACHABLE;
				}
			}
		}

		void addEdges(String info) {
			StringTokenizer st = new StringTokenizer(info, ",");
			int a, b, c, d;
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			c = Integer.parseInt(st.nextToken());
			d = Integer.parseInt(st.nextToken());

			adjacency[a][b] = c;
			adjacency[b][a] = d;

		}

		int dijkstra(int start, int goal) {

			boolean[] checked = new boolean[length];
			int[] total = new int[length];
			int next;

			for (int i = 1; i < length; ++i) {
				total[i] = INFINITY;
			}

			total[start] = 0;
			next = start;
			while (next != UNREACHABLE) {

				int s = next;
				checked[s] = true;

				for (int g = 1; g < length; ++g) {
					if (adjacency[s][g] != UNREACHABLE) {
						if (total[g] > total[s] + adjacency[s][g]) {
							total[g] = total[s] + adjacency[s][g];
						}
					}
				}

				int min = INFINITY, idx = UNREACHABLE;
				for (int g = 1; g < length; ++g) {
					if (!checked[g] && min > total[g]) {
						min = total[g];
						idx = g;
					}
				}

				next = idx;
			}

			return total[goal];
		}
	}
}

Measured memory_bytes: 16872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H, W; cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  vector<vector<int>> B(H, vector<int>(W));
  rep(y,H) rep(x,W) cin >> A[y][x];
  rep(y,H) rep(x,W) cin >> B[y][x];
  vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(25603, false)));
  dp[0][0][abs(A[0][0]-B[0][0])] = true;
  rep(y,H){
    rep(x,W){
      rep(k, 25603){
        if(dp[y][x][k]){
          if(x != W-1){
            dp[y][x+1][k+abs(A[y][x+1]-B[y][x+1])] = true;
            dp[y][x+1][abs(k-abs(A[y][x+1]-B[y][x+1]))] = true;
          }
          if(y != H-1){
            dp[y+1][x][k+abs(A[y+1][x]-B[y+1][x])] = true;
            dp[y+1][x][abs(k-abs(A[y+1][x]-B[y+1][x]))] = true;
          }
        }
      }
    }
  }
  rep(k, 25603){
    if(dp[H-1][W-1][k]){
      cout << k << endl;
      break;
    }
  }
  return 0;
}


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

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int h = scan.nextInt();
            int w = scan.nextInt();
            
            if(h < 3) break;
            
            for(int i = 0; i < h; ++i){
                for(int j = 0; j < w; ++j){
                    System.out.print(i == 0 || i + 1 == h || j == 0 || j + 1 == w ? '#' : '.');
                }
                System.out.println();
            }
            
            System.out.println();
        }
    }
}


Measured memory_bytes: 36184
#include <cstdio>
#include <algorithm>
using namespace std;

#define INF 0x7fffffff

int n;
int field[101][101];
int imos[101][101];

int main() { 
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      scanf("%d", &field[i][j]);
    }
  }

  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      imos[i][j] += imos[i][j-1] + field[i][j];
    }
  }

  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      imos[i][j] += imos[i-1][j];
    }
  }

  int ans = -INF;
  for (int i=1; i<=n; i++) {
    for (int j=i; j<=n; j++) {
      for (int k=1; k<=n; k++) {
        for (int l=k; l<=n; l++) {
          ans = max(ans, imos[j][l] - imos[i-1][l] - imos[j][k-1] + imos[i-1][k-1]);
        }
      }
    }
  }

  printf("%d\n", ans);
}

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

int main() {

int src;
int num[4];
int chain = 1;

cin >> src;
num[0] = src / 1000;
num[1] = (src - num[0]*1000) / 100;
num[2] = (src - num[0]*1000 - num[1]*100) / 10;
num[3] = (src - num[0]*1000 - num[1]*100 - num[2]*10) / 1;

for(int i=1; i<=3; i++)
{
    if(num[i] == num[i-1]) 
        chain = chain + 1;
    else
        chain = 1;
    if (chain == 3) break;
}

if(chain >= 3)
    cout << "Yes" << endl;
else
    cout << "No" << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String[] test=new String[n];
		for(int i=0;i<n;i++)test[i]=sc.next();
		int[] cnt={0,0,0,0};
		for(int i=0;i<n;i++)
		{
			switch(test[i])
			{
			case "AC":
				cnt[0]++;
				break;
			case "WA":
				cnt[1]++;
				break;
			case "TLE":
				cnt[2]++;
				break;
			case "RE":
				cnt[3]++;
				break;
			}
		}
		System.out.println("AC x "+cnt[0]);
		System.out.println("WA x "+cnt[1]);
		System.out.println("TLE x "+cnt[2]);
		System.out.println("RE x "+cnt[3]);
		sc.close();
	}
}


Measured memory_bytes: 64236
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args){
        int n = sc.nextInt(),K = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int left = 0;
        ArrayList<int[]> feet = new ArrayList<>();
        while(left<n){
            if(s[left]=='1') {
                left++;
                continue;
            }
            int right = left;
            while(right<n&&s[right]=='0') right++;
            feet.add(new int[]{left,right-1});
            left = right;
        }
        int ans = feet.size()==0?n:0;
        for(int i=0;i<feet.size();i++){
            left = i==0?0:(feet.get(i-1)[1]+1);
            int riIdx = Math.min(i+K-1,feet.size()-1);
            int right = riIdx==feet.size()-1?(n-1):(feet.get(riIdx+1)[0]-1);
            ans = Math.max(ans,right-left+1);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 33096
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==0){
        cout << a-b << endl;
    }else{
        cout << b-a << endl;
    }
    return 0; 
}

Measured memory_bytes: 3516
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=310;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[N][N],cur[N];
int cnt[N];
int main()
{
	int n=gi(),m=gi(),i,j,k,l,r,mid;
	set<int>s;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			a[i][j]=gi();
	l=1,r=n;
	while (l!=r) {
		mid=(l+r)>>1;
		s.clear();
		for (i=1;i<=m;i++) cnt[i]=0;
		for (i=1;i<=n;i++) if (++cnt[a[i][cur[i]=1]]>mid) s.insert(a[i][1]);
		for (i=1;i<=m;i++) {
			if (s.empty()) break;
			k=*s.begin();s.erase(s.begin());
			for (j=1;j<=n;j++)
				if (a[j][cur[j]]==k) {
					while (cur[j]<=m&&cnt[a[j][cur[j]]]>mid) cur[j]++;
					if (++cnt[a[j][cur[j]]]>mid) s.insert(a[j][cur[j]]);
				}
		}
		if (i<=m) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}


Measured memory_bytes: 640
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
 */
#include <iostream>
#include <vector>

using namespace std;

int
checkfit(const vector<int> &w, const int p)
{
    int count = 1;
    int load = 0;
    for (int it : w) {
        if (load + it > p) {
            load = it;
            count++;
        } else {
            load += it;
        }
    }
    return count;
}

int
main()
{
    ios_base::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k; cin.ignore();

    vector<int> w(n);
    int total = 0;
    int wmax = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i]; cin.ignore();
        total += w[i];
        if (w[i] > wmax) wmax = w[i];
    }

    int p = max(total / k, wmax);
    while (checkfit(w, p) > k) p++;

    cout << p << endl;
    return 0;
}

Measured memory_bytes: 3368
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>

int main()
{
	int x1, y1, x2, y2;
	std::cin >> x1 >> y1 >> x2 >> y2;
	
	int n;
	std::pair<int, int> point[200010];
	std::cin >> n;
	
	for (int i = 0; i < n; ++i)
		std::cin >> point[i].first >> point[i].second;
	
	if (x1 > x2)
	{
		x1 = 100000000 - x1;
		x2 = 100000000 - x2;
		for (int i = 0; i < n; ++i)
			point[i].first = 100000000 - point[i].first;
	}
	if (y1 > y2)
	{
		y1 = 100000000 - y1;
		y2 = 100000000 - y2;
		for (int i = 0; i < n; ++i)
			point[i].second = 100000000 - point[i].second;
	}
	
	std::vector< std::pair<int, int> > points;
	for (int i = 0; i < n; ++i)
	{
		if (point[i].first >= x1 && point[i].first <= x2 && point[i].second >= y1 && point[i].second <= y2)
			points.push_back(point[i]);
	}
	
	std::sort(points.begin(), points.end());
	
	int length = 0, dist[200010] = { 0 };
	long double pi = 3.14159265358979323;
	for (int i = 0; i < points.size(); ++i)
	{
		int value = points[i].second;
		int temp = std::lower_bound(dist, dist + length, value) - dist;
		if (temp == length)
			++length;
		
		dist[temp] = points[i].second;
	}
	
	long double ans = 100.0 * (x2 - x1 + y2 - y1);
	ans += (5 * pi - 20) * length;
	
	if (length == std::min(x2 - x1, y2 - y1) + 1)
		ans += 5 * pi;
	
	std::cout << std::fixed << std::setprecision(18) << ans;
}

Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <utility>

int main() {
		
	// recieve |V| and |E|
	int V, E; std::cin >> V >> E;
	std::vector<std::vector<std::pair<int, int>>> G(V);
	
	for(int i = 0; i < E; i++) {
		// recieve edges
		int u, v, d; std::cin >> u >> v >> d;
		u--; v--;
		G[u].push_back({v, d});
		G[v].push_back({u, d});
	}
	
	int Tmax; std::cin >> Tmax;

	// recieve info
	for(int i = 0; i < Tmax; i++) {
		int Nnew; std::cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			int new_id, dst; std::cin >> new_id >> dst;
		}
	}

  // insert your code here to get more meaningful output
	// all stay
	for(int i = 0; i < Tmax; i++) std::cout << -1 << std::endl;
	return 0;
}


Measured memory_bytes: 888
#define maxn 105
#include<bits/stdc++.h>
using namespace std;

const int inf = 1e9 + 2;
int profit[maxn], cost[maxn];
int dp[100005];

int main(){
    int n, cap;
    cin >> n >> cap;
    for(int i=1;i<=n;i++){
        cin >> cost[i] >> profit[i];
    }
    for(int i=1;i<=100002;i++){
        dp[i] = inf;
    }
    for(int i=1;i<=n;i++){
        for(int j=100002;j>=1;j--){
            if(j-profit[i] >= 0){
                dp[j] = min(dp[j], dp[j-profit[i]] + cost[i]);
            }
        }
    }
    int mx = 0;
    //for(int i=0;i<=30;i++) cout << dp[i] << " ";cout << endl;
    for(int i=1;i<=100002;i++){
        if(dp[i] <= cap && dp[i]<inf){
            mx = i;
        }
    }
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 640