akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

struct Card{
  char suit;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].suit, &C1[i].value);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N; cin >> N;
    string s; cin >> s;

    set<int> s1, s2, s3;

    rep(i, N){
        for(auto x : s2) s3.insert(10*x + s[i]-'0');
        for(auto x : s1) s2.insert(10*x + s[i]-'0');
        s1.insert(s[i]-'0');
    }

    cout << s3.size() << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;

int sum(int a){
  int c=0;
  while(a>=10){
    c+=a%10;
    a/=10;
  }
  c+=a;
  return c;
}

int main(){
  int n,a,b; cin>>n>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
    int s=sum(i);
    if(a<=s&&s<=b)
    ans+=i;
  }
  cout<<ans<<endl;

  return 0;
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

int main() {
    int N;
    cin >> N;
    int s = 0;
    REP(i, N) {
        int l, r;
        cin >> l >> r;
        s += r - l + 1;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <math.h>
#include<cstdio>
#include<iomanip>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  for(int i=1; i<=N; i++){
    int n = i;
    int cnt = 0;
    while(n < K){
      n *= 2;
      cnt ++;
    }
    ans += (double)1.0/(double)N * pow(1.0/2.0, (double)cnt);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline bool isprime(i32 n) { if (n < 2) return 0; for (i32 i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; }
inline vi32 plist(i32 n) { vi32 f(n, 1); f[0] = f[1] = 0; repi(i, 2, n) for (int j = i * 2; j < n; j += i) f[j] = 0; return f; }
inline void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
template<class T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<class T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<class T> inline bool amax(T &x, T y) { if (x >= y) return 0; x = y; return 1; }
template<class T> inline bool amin(T &x, T y) { if (x <= y) return 0; x = y; return 1; }
template<class T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<class T> vector<T> make_v(int n, T v) { return vector<T>(n, v); }
template<class... Ts> auto make_v(int n, Ts... ts) { return vector<decltype(make_v(ts...))>(n, make_v(ts...)); }

int main() {
  ioinit();
  int h, w;
  cin >> h >> w;
  auto board = make_v(h, w, (int) 1e9);
  vstr a(h);
  rep(i, h) cin >> a[i];
  rep(i, h) rep(j, w) if (a[i][j] == '#') board[i][j] = 0;
  rep(i, h) rep(j, w - 1) amin(board[i][j + 1], board[i][j] + 1);
  rep(i, h) rrep(j, w - 1) amin(board[i][j], board[i][j + 1] + 1);
  rep(i, w) rep(j, h - 1) amin(board[j + 1][i], board[j][i] + 1);
  rep(i, w) rrep(j, h - 1) amin(board[j][i], board[j + 1][i] + 1);
  rep(i, h) rep(j, w - 1) amin(board[i][j + 1], board[i][j] + 1);
  rep(i, h) rrep(j, w - 1) amin(board[i][j], board[i][j + 1] + 1);
  rep(i, w) rep(j, h - 1) amin(board[j + 1][i], board[j][i] + 1);
  rep(i, w) rrep(j, h - 1) amin(board[j][i], board[j + 1][i] + 1);
  int ans = 0;
  rep(i, h) rep(j, w) amax(ans, board[i][j]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1;i<=n;i++) {
        ll N = n/i;
        ans += i*N*(N+1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
 
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   
       int n, m;
       cin>>n>>m;
       cout <<( n*(n - 1)) / 2+(m*(m-1))/2;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a,b;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		b.pb(x);
	}
	int ans = inf;
	for(int i=0;i<(1<<n);i++){
		int cnt = 0;
		int cur = i;
		vector< pair<int,int> > odd;
		vector< pair<int,int> > even;
		for(int j=0;j<n;j++){
			int fl = cur%2;
			cur /= 2;
			if( (fl+j) % 2 == 0 ){
				if( fl == 0 ){
					even.pb( mp( a[j], j ) );
				}
				else{
					even.pb( mp( b[j], j ) );
				}
			}
			else{
				if( fl == 0 ){
					odd.pb( mp( a[j], j ) );
				}
				else{
					odd.pb( mp( b[j], j ) );
				}
			}
		}
		if( even.size() == (n+1)/2 && odd.size() == n/2 ){
			sort( odd.begin(), odd.end() );
			sort( even.begin(), even.end() );
			vector<int> al,aln;
			for(int j=0;j<n;j++){
				if( j%2 == 0 ){
					al.pb( even[j/2].second );
					aln.pb( even[j/2].first );
				}
				else{
					al.pb( odd[j/2].second );
					aln.pb( odd[j/2].first );
				}
			}
			bool f = true;
			for(int j=0;j<n-1;j++){
				if( aln[j] > aln[j+1] ) f = false;
			}
			if( f == true ){
				int pos[20];
				for(int j=0;j<n;j++){
					pos[j] = j;
				}
				int res = 0;
				for(int j=0;j<n;j++){
					res += pos[ al[j] ] - j;
					for(int k=0;k<al[j];k++){
						pos[k]++;
					}
				}
				if( res < ans ) ans = res;
			}
		}
	}
	if( ans == inf ){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)x.size()

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  unsigned int x;
  cin >> x;
  cout << 1000*(x/500) + 5*((x-500*(x/500))/5);

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
        Scanner sc1 = new Scanner(System.in);
        int a = sc1.nextInt();
        int b = sc1.nextInt();
        int c = sc1.nextInt();
        if(a == 7 && b == 5 && c == 5){
            System.out.print("YES");
        }else if(a == 5 && b == 7 && c == 5){
            System.out.print("YES");
        }else if(a == 5 && b == 5 && c == 7){
            System.out.print("YES");
        }else{
            System.out.print("NO");
        }
    }
}

Measured memory_bytes: 21588
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i)
{
    int l, r, largest;
    l = 2*i;
    r = 2*i+1;

    if(l<=H && A[l]>A[i]) largest = l;
    else largest = i;
    if(r<=H && A[r]>A[largest]) largest = r;

    if(largest != i)
    {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main()
{
    cin >> H;
    for(int i=1; i<=H; i++) cin >> A[i];
    for(int i=H/2; i>=1; i--) maxHeapify(i);
    for(int i=1; i<=H; i++) cout << " " << A[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 4944
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val xs = readLine()!!.split(" ").map { it.toLong() }.sorted()

    val dist = mutableListOf<Long>()
    for (i in 0 until xs.size - 1) {
        val d = Math.abs(xs[i] - xs[i + 1])
        dist.add(d)
    }

    val ans = dist.sortedDescending().drop(n - 1).sum()
    println(ans)
}

Measured memory_bytes: 55508
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int h, w;
string s[50];

bool alone(int y, int x)
{
    rep(i, 0, 4)
    {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < w && ny >= 0 && ny < h)
        {
            if (s[ny][nx] == '#')
                return false;
        }
    }
    return true;
}

int main()
{

    cin >> h >> w;
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (s[i][j] == '#' && alone(i, j))
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 0, id = 1;
  bool ok = false;
  rep(i, n) {
    if (a[i] == id) {
      ok = true;
      id++;
    } else {
      ans++;
    }
  }
  if (ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
def main():
  N = int(input())
  A = list(map(int, input().split()))
  rank = [[] for _ in range(N)]

  for i in range(N):
    rank[A[i]-1] = i + 1
  
  print(' '.join(map(str,rank)))


if __name__ == '__main__':
  main()

Measured memory_bytes: 18756
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
def main():
    N, D, A = MI()
    Enemy = defaultdict()
    Enemy_ran = []
    for i in range(N):
        x, h = MI()
        Enemy[x] = h
        Enemy_ran.append(x)
    Enemy_ran.sort()
    cnt = 0
    dam_list = deque()
    dam_all = 0
    for i in range(N):
        x = Enemy_ran[i]
        while len(dam_list) != 0 and i >= dam_list[0][0]:
            dam_all -= dam_list.popleft()[1]
        HP = Enemy[x] - dam_all
        if HP <= 0:
            continue
        else:
            ata = math.ceil(Decimal(HP) / Decimal(A))
            cnt += ata
            ran = x + 2 * D
            y = bisect.bisect_right(Enemy_ran, ran)
            dam = ata * A
            dam_list.append((y, dam))
            dam_all += dam


    print(cnt)


if __name__ == "__main__":
    main()



Measured memory_bytes: 273952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a == b + c || b == a + c || c == a + b) Yes();
  else No();
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, cnt int
	fmt.Scan(&n)

	for a := 1; a < n; a++ {
		for b := a; b < n; b++ {
			if a*b < n {
				cnt++
				if a != b {
					cnt++
				}
			} else {
				break
			}
		}
		if a*a >= n {
			break
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define LLMAX 1000000000000000000
#define pic pair<ll,char>

ll a, b;

int main()
{
	cin >> a >> b;
	int ct = 0;
	while(a<=b)
	{
		ct++; a*=2;
	}
	cout<<ct<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

vector<int> get_lens(string s, int size) {
    vector<int> ret;
    int c = 1;
    char ch = s[0];
    if (ch == '0') ret.push_back(0);
    FOR(i, 1, size) {
        if (s[i] != ch) {
            ret.push_back(c);
            ch = s[i];
            c = 1;
        }
        else c++;
    }
    if (c != 0) ret.push_back(c);
    if (s[size - 1] == '0') ret.push_back(0);
    return ret;
}

int main() {
    int N, K;
    string s;
    cin >> N >> K >> s;
    vector<int> lens = get_lens(s, N);

    int sum = 0;
    REP(i, 2 * K + 1) {
        sum += lens[i];
        if (i >= lens.size() - 1) {
            cout << N << endl;
            return 0;
        }
    }
    int s_max = sum, l = 0, r = 2 * K + 1;
    while (r < lens.size()) {
        sum -= lens[l] + lens[l + 1];
        sum += lens[r] + lens[r + 1];
        l += 2;
        r += 2;
        s_max = max(s_max, sum);
    }

    cout << s_max << endl;
    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int V,E;
int dist[111111];
vector<pair<int,int>> G[111111];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>V>>E;
    for(int i=0;i<E;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,-c});
    }
    fill(dist,dist+111111,-2e9);
    for(int i=0;i<V;i++){
        if(dist[i]==-2e9){
            int lo=0,hi=0;
            dist[i]=0;
            queue<int>q;
            q.push(i);
            while(!q.empty()){
                auto qf=q.front();
                q.pop();
                for(auto adj:G[qf]){
                    int v=adj.first;
                    int d=adj.second;
                    if(dist[v]==-2e9){
                        dist[v]=dist[qf]+d;
                        lo=min(lo,dist[v]);
                        hi=max(hi,dist[v]);
                        q.push(v);
                        if(hi-lo>1e9){
                            cout<<"No";
                            return 0;
                        }
                    }
                    else if(dist[v]!=dist[qf]+d){
                        cout<<"No";
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 9728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		char[] letters = scanner.next().toCharArray();
		int ans = 0;
		int count = 0;
		
		for (int i = 0; i < n; i++) {
			if (letters[i]=='I') {
				count++;
			}else {
				count--;
			}
			if (count>ans) {
				ans = count;
			}
		}
		
		System.out.println(ans);
		scanner.close();
	}

}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
	static int modAns = (int)Math.pow(10, 9) + 7;
	static long fac[] = new long[1000000];
	static long finv[] = new long[1000000];
	static long inv[] = new long[1000000];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int length = sc.nextInt();
		int multi = sc.nextInt();
		long ans = 1;
		ArrayList<Integer> counts = new ArrayList<Integer>();
		for(int i = 2; i <= multi; i ++) {
			if(multi % i == 0) {
				int count = 0;
				while(multi % i == 0) {
					multi /= i;
					count ++;
				}
				counts.add(count);
			}
			if(multi == 1) { break; }
		}
		COMinit();
		for(int i = 0; i < counts.size(); i ++) {
			ans *= combi(counts.get(i) + length - 1, Math.min(counts.get(i), length - 1)) % modAns;
			ans %= modAns;
		}
		System.out.println(ans);
	}

	public static long combi(int n, int r) {
		return fac[n] * (finv[r] * finv[n - r] % modAns) % modAns;
	}

	public static void COMinit() {
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < fac.length; i++){
				fac[i] = fac[i - 1] * i % modAns;
				inv[i] = modAns - inv[modAns%i] * (modAns / i) % modAns;
				finv[i] = finv[i - 1] * inv[i] % modAns;
		}
	}
}

Measured memory_bytes: 48596
# ABC159

def is_kaibun(string):

    for i in range((len(string)//2)+1):
        if string[i] != string[len(string)-i-1]:
            return False
    else:
        return True


S = input()
if is_kaibun(S) and is_kaibun(S[0:(len(S)-1)//2]) and is_kaibun(S[((len(S)+3)//2)-1:len(S)]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9084
import java.io.*;
import java.util.*;
 
public class Main{
  	public static void main(String[] args)throws Exception{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      int n=Integer.parseInt(br.readLine());
      String s=br.readLine();
      if(n>=3200){
       System.out.println(s); 
      }else{
        System.out.println("red");
      }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 100010;
int n, ans[N];
VI e[N], id[N];

void dfs(int now, int past, int c, int k){
    c = (c + 1) % k;
    REP(i,e[now].size()){
        int next = e[now][i];
        if (next == past) continue;
        ans[id[now][i]] = c;
        dfs(next, now, c, k);
        c = (c + 1) % k;
    }
}

int main() {
    cin >> n;
    VI deg(n);
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
        id[u].push_back(i);
        id[v].push_back(i);
        deg[u]++;
        deg[v]++;
    }

    int k = *max_element(ALL(deg));
    dfs(0, -1, -1, k);

    cout << k << endl;
    REP(i,n-1){
        printf("%d\n", ans[i] + 1);
    }

    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep (i, n) cin >> a[i];
    int r = 0;
    ll sum = 0, ans = 0;
    rep (l, n) {
        while (r < n && (sum + a[r]) == (sum ^ a[r])) {
            sum += a[r];
            r++;
        }
        ans += r - l;
        if (r == l) r++;
        else
            sum ^= a[l];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const long long MOD=1000000007LL;
long long n,k,dp[200100],ans;
long long pw(long long a,long long b){
	long long res=1LL;
	while(b){
		if(b&1)
			res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res%MOD;
}
int main()
{
	cin>>n>>k;
	for(int i=k;i>=1;i--)
	{
		long long mx=k/i,cnt=pw(mx,n);
		for(int j=i+i;j<=k;j+=i)
		{
			cnt=(cnt+MOD-dp[j])%MOD;
		}
		dp[i]=cnt;
		cnt*=(i*1ll);
		cnt%=MOD;
		ans+=cnt;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	clock_t start = clock();
	int D;
	cin >> D;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	vector<int> t(D);
	vector<vector<int>> last(D, vector<int>(26, 0));
	vector<int> sat(D);
	vector<int> sat_tmp(26);

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

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}

	/*********************************/
	for (int i = 0; i < D; i++) {
		for (int k = 0; k < 26; k++) {
			for (int j = 0; j < 26; j++) {
				if (i == 0) {
					last[i][j] = 0;
				} else {
					last[i][j] = last[i - 1][j];
				}
			}
			last[i][k] = i + 1;
			if (i == 0) {
				sat_tmp[k] = s[i][k];
			} else {
				sat_tmp[k] = s[i][k] + sat_tmp[i - 1];
			}
			int satisfaction = 0;
			for (int j = 0; j < 26; j++) {
				satisfaction += c[j] * (i + 1 - last[i][j]);
			}
			sat_tmp[k] -= satisfaction;
		}
		vector<int>::iterator iter = max_element(sat_tmp.begin(), sat_tmp.end());
		size_t index = distance(sat_tmp.begin(), iter);
		t[i] = index;

		for (int j = 0; j < 26; j++) {
			if (i == 0) {
				last[i][j] = 0;
			} else {
				last[i][j] = last[i - 1][j];
			}
		}
		last[i][t[i]] = i + 1;
		if (i == 0) {
			sat[i] = s[i][t[i]];
		} else {
			sat[i] = s[i][t[i]] + sat[i - 1];
		}
		int satisfaction = 0;
		for (int j = 0; j < 26; j++) {
			satisfaction += c[j] * (i + 1 - last[i][j]);
		}
		sat[i] -= satisfaction;
	}

	// for (int i = 0; i < D; i++) {
	// 	cout << sat[i] << endl;
	// }
	int max_sat = sat[D - 1];
	/*********************************/
	vector<int> t_new(D);
	std::srand(time(NULL));

	while (clock() - start < 1975000) {
		t_new = t;
		t_new[rand() % D] = rand() % 26;

		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				if (i == 0) {
					last[i][j] = 0;
				} else {
					last[i][j] = last[i - 1][j];
				}
			}
			last[i][t_new[i]] = i + 1;
			if (i == 0) {
				sat[i] = s[i][t_new[i]];
			} else {
				sat[i] = s[i][t_new[i]] + sat[i - 1];
			}
			int satisfaction = 0;
			for (int j = 0; j < 26; j++) {
				satisfaction += c[j] * (i + 1 - last[i][j]);
			}
			sat[i] -= satisfaction;
		}
		if (sat[D - 1] > max_sat) {
			// cout << sat[D - 1] << endl;
			max_sat = sat[D - 1];
			t = t_new;
		}
	}

	/*********************************/

	for (int i = 0; i < D; i++) {
		cout << t[i] + 1 << endl;
	}
	// cout << sat[D - 1] << endl;
	// cout << clock() - start << endl;

	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
const double PI  = 3.141592653589793;
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}


void solve() {
    int a,b,x;
    cin >> a >> b >> x;
    int v = a * a * b;
    if (x * 2 == a * a * b) {
        cout << 45 << endl;
        return;
    }
    if (x * 2 < a * a * b) {
        double r = atan((double)1.0 * b / (2.0 * x / (a * b)));
        printf("%.7lf\n", r * 180 / (PI));
    } else {
        double y = 2.0 * x / (a * a) - b;
        double diff = b - y;
        double r = atan(diff / a);
        printf("%.7lf\n", r * 180 / (PI));
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    long long i,n,a[11],max=0,sum=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(a[i]>a[max])
			max=i;
		sum+=a[i];
	}
	printf("%lld\n",sum-a[max]+a[max]/2);
	
    
}

Measured memory_bytes: 256
n = int(input())
s = input()
a = []

def getConverseCodes(args, i):
	converseCodes = ''
	for s in args:
		s = ord(s)
		if 65 <= s and s<= 90:
			s = s + i
		elif 97 <= s and s <= 122:
			s = s + i
		#アスキーコードから文字を取得
		if s >= 91:
			s -= 26
		s = chr(s)
		converseCodes += s
	return converseCodes

for i in range(len(s)):
	a.append(getConverseCodes(s[i],n))
print ("".join(a))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(){
	long x = -1, i, N;
	char s[100000], t = 'A';
	scanf("%s", s);
	N = strlen(s);
	for(i = 0; i < N; i ++){
		if(s[i] != t){
			x ++;
			t = s[i];
		}
	}
	printf("%ld\n", x);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string itos(int n){
  stringstream ss;
  ss<<n;
  return ss.str();
}
int stoi(string s){
  return atoi(s.c_str());
}
int solve(int n){
  int ans = 0;
  while(true){
    string s = itos(n);
    if(s.size() <= 1) break;
    ans ++;
    int next = 0;
    for(int i = 1; i < s.size(); i++){
      string b = s.substr(0, i), e = s.substr(i);
      next = max(next, stoi(b) * stoi(e));
    }
    n = next;
  }
  return ans;
}

int main(){
  int N;
  while(cin>>N){
    while(N--){
      int n; cin>>n;
      cout<<solve(n)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
 
using namespace std;
 
void solve();
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
 
void solve() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i = 0; i <= a; i++) {
        for(int j = 0; j <= b; j++) {
             int tmp = x - i * 500 - j * 100;
             if(tmp % 50 == 0 && tmp / 50 <= c && tmp >= 0) {
                 //cout << i << " " << j << " " << tmp << endl;
                 ans++;
             }
        }
    }
    cout << ans << endl;
    

}

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

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

using namespace std;

int main(void) {
    int h, w;
    cin >> h >> w;

    int canvas[h][w];
    REP(i, h) {
        REP(j, w) {
            char input;
            cin >> input;
            if (input == '.') canvas[i][j] = 0;
            else canvas[i][j] = 1;
        }
    }

    REP(i, h) {
        REP(j, w) {
            if (canvas[i][j] == 1) {
                if (canvas[i-1][j] == 0 &&
                    canvas[i+1][j] == 0 &&
                    canvas[i][j-1] == 0 &&
                    canvas[i][j+1] == 0) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
long long a[5005],sum;
int main(){
	ios_base::sync_with_stdio(false);
	long long i,j,n,x,t,ans=0;
	cin>>n>>x;
	for(i=0;i<n;i++) cin>>a[i],sum+=a[i];
	if(sum<x){
		cout<<n<<endl;
		return 0;
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(i=0;i<n;i++){
		t=x;
		for(j=0;j<n;j++){
			if(i==j) continue;
			if(t>a[j]) t-=a[j];
		}
		if(t<=a[i]) ans++;
	} 
	cout<<n-ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector <vector<int>> data(3 ,vector <int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>data[i][j];
        }
    }
    queue<pair<int,int>> q1;  //b0,a2
    for(int i=0;i<=data[2][0];i++){
        q1.push(make_pair(i,data[2][0]-i));
    }
    queue<tuple<int,int,int,int>> q2;
    while(q1.size()!=0){
        pair <int,int> tmp=q1.front(); q1.pop();
        int a1=data[1][0]-tmp.first ,b1=data[2][1]-tmp.second;
        if(a1+b1==data[1][1]) { //a1,a2,b0,b1
            q2.push(make_tuple(a1,tmp.second,tmp.first,b1));
        }
    }
    while(q2.size()!=0){
        tuple<int,int,int,int> tmp= q2.front(); q2.pop();
        int a1=get<0>(tmp),a2=get<1>(tmp),b0=get<2>(tmp),b1=get<3>(tmp);
        int a0= data[0][0]-b0, b2=data[2][2]-a2;
        if(data[0][1]==b1+a0&&data[0][2]==a0+b2&&data[1][2]==a1+b2){
            cout<<"Yes"<<endl; return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int k = int.Parse(cin[1]);
        int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

        var dic = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            if (dic.ContainsKey(a[i])) dic[a[i]]++;
            else dic.Add(a[i], 1);
        }

        List<KeyValuePair<int, int>> list = dic.ToList();
        list.Sort(Compare);

        int ans = 0;
        for (int i = 0; i < list.Count - k; i++)
        {
            ans += list[i].Value;
        }
        Console.WriteLine(ans);
    }

    static int Compare(KeyValuePair<int, int> a, KeyValuePair<int, int> b)
    {
        return a.Value - b.Value;
    }
}


Measured memory_bytes: 43984
<?php
fscanf(STDIN, "%d",$cnt);
fscanf(STDIN, "%s",$moji);
fscanf(STDIN, "%d",$ban);

$t=substr($moji,$ban-1,1);

$m="";

for($i=0;$i<$cnt;$i++){
	if(substr($moji,$i,1)==$t){
		$m=$m.$t;
	}else{
		$m=$m."*";
	}
}

echo $m;
?>

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

struct Edge{
    int to;     //辺の行先
    ll cost; //辺の重み
    Edge(int t, ll w) : to(t), cost(w) {}
};

/* dijkstra(G,s,dis)
    入力:グラフ G, 開始点 s,距離を格納する dis
    計算量 : O(|E|log|V|)
    副作用 : disが書き換えられる
*/
using Graph = vector<vector<Edge>>;
using P = pair<ll,int>;
void dijkstra(const Graph &G, int s, int goal, vector<ll> &dis, vector<vector<int>> &prev){
    int N = G.size();
    dis.resize(N,INF);  // Gの大きさで初期化
    prev.resize(N);
    priority_queue<P,vector<P>,greater<P>> pq; // [仮の最短経路,頂点]が小さい順で並ぶ
    dis[s] = 0; //スタート地点の距離は0
    pq.emplace(dis[s],s); // スタート地点を代入
    while(!pq.empty()){
        P p = pq.top(); // 最短経路が一番小さいものを取得
        pq.pop();
        int V = p.second; // 頂点
        if(dis[V] < p.first){ // 最短経路で無い場合は無視
            continue;
        }
        if(V == goal) continue;
        for (auto &e : G[V]) {
            if(dis[e.to] >= dis[V] + e.cost) { //最短経路なら
                if(dis[e.to] > dis[V] + e.cost) prev[e.to].clear();
                dis[e.to] = dis[V] + e.cost;
                prev[e.to].push_back(V); //頂点vを通って　e.toにたどり着いた
                pq.emplace(dis[e.to],e.to);
            }
        }   
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    set<pair<int,int>> edge;
    Graph G(n+1);
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(Edge(b,c));
        G[b].push_back(Edge(a,c));
        edge.insert(make_pair(a,b));
    }
    for(int stt =0; stt < n-1; stt++){
        for(int goal = stt+1;goal < n;goal++){
            vector<ll> dis;
            vector<vector<int>> prev;
            dijkstra(G,stt,goal,dis,prev);
            queue<int> que;
            que.push(goal);
            while(!que.empty()){
                int v = que.front();
                que.pop();
                rep(i,prev[v].size()){
                    int vb = prev[v][i];
                    edge.erase({vb,v});
                    edge.erase({v,vb});
                    que.push(vb);
                }   
            }
        }

    }
    cout << edge.size() << endl;
    return 0;
}

Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
int A[81][81], B[81][81];
bool dp[81][81][80*80*2+5] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    rep(i,0,H){
        rep(j,0,W){
            cin >> A[i][j];
        }
    }
    rep(i,0,H){
        rep(j,0,W){
            cin >> B[i][j];
        }
    }
    // rep(i,0,H){
    //     rep(j,0,W){
    //         rep(k,0,161){
    //             dp[i][j][k] = I
    //         }
    //     }
    // }
    ll thre = 80*80;
    ll v = abs(A[0][0] - B[0][0]);
    dp[0][0][thre + v] = 1;
    rep(i,0,H){
        rep(j,0,W){
            rep(k,0,80*80*2+2){
                if(i+1 < H){
                    ll tt = abs(A[i+1][j] - B[i+1][j]);
                    if(dp[i][j][k]){
                        dp[i+1][j][k+tt] = true;
                        dp[i+1][j][k-tt] = true;
                    }
                }
                if(j+1 < W){
                    ll tt = abs(A[i][j+1] - B[i][j+1]);
                    if(dp[i][j][k]){
                        dp[i][j+1][k+tt] = true;
                        dp[i][j+1][k-tt] = true;
                    }
                }
            }
        }
    }
    ll ans = INF;
    rep(k,0,80*80*2+2){
        if(dp[H-1][W-1][k]){
            ans = min(ans, abs(k - thre));
        }
    }
    print(ans);


    

}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            char[] s = inp.next().toCharArray();
            char[] t = inp.next().toCharArray();
            int m = s.length, n = t.length;
            int[][] dp = new int[m+1][n+1];
            for (int i = 1; i <= m; i++) {
                for (int j = 1; j <= n; j++) {
                    if (s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
                    else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
            int a = m, b = n;
            StringBuilder res = new StringBuilder();
            while (res.length() < dp[m][n]) {
                if (dp[a][b] != dp[a][b-1]) {
                    char c = t[b-1];
                    res.append(c);
                    while (s[a-1] != c) a--;
                    a--;
                }
                b--;
            }
            out.println(res.reverse().toString());
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 80212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  ll D,G;
  cin >> D >> G;
  vector<ll> p(D),c(D);
  for(int i = 0; i < D; i++){
    cin >> p[i] >> c[i];
  }

  int ans = 1e9;
  for(int mask = 0; mask < (1 << D); mask++){
    int s = 0; int num = 0; int res_max = -1;
    for(int i = 0; i < D; i++){
      if((mask >> i) & 1){
	s += 100 * (i+1) * p[i] + c[i];
	num += p[i];
      }else{
	res_max = i;
      }
    }

    if(s < G){
      int s1 = 100 * (res_max + 1);
      int res = (G - s + s1 - 1) / s1;
      if(res >= p[res_max]){
	continue;
      }
      num += res;
    }

    ans = min(ans, num);
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 5007;
int n, mod;
inline void add(int &x, int y) {x += y; if (x >= mod) x -= mod;}
inline int mul(int x, int y) {ll res = (ll)x * y; res -= res / mod * mod; return res;}
int dp[MAXN], w[MAXN];
int main()
{
    scanf("%d%d", &n, &mod);
    for (int i = 1, j = n - 1, c = 1; i <= j; i++, j--, c++) w[j] = c + 1, w[i] = c;
    dp[0] = 1;
    for (int i = 1; i < n; i++)
        for (int j = w[i]; j < n; j++) add(dp[j], dp[j - w[i]]);
    int ans = 0;
    for (int i = 0; i < n; i++) add(ans, mul(dp[i], n - i));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
H,W = map(int,input().split())
grid = [[0]*W for _ in range(H)]
for i in range(H):
    grid[i] = list(map(int, input().split()))

done = [[0]*W for _ in range(H)]

def nex(y,x):
    for new_y,new_x in [[y,x+1],[y+1,x],[y-1,x],[y,x-1]]:
        if 0<=new_y<H and 0<=new_x<W and not done[new_y][new_x]:
            return [new_y,new_x]
    return False

ans_ls = []
y,x = 0,0
if grid[y][x] % 2 == 1:
    previous_y, previous_x = y,x
    have_odd = True
else:
    have_odd = False

while True:
    if not nex(y,x):
        break
    y,x  = nex(y,x)
    done[y][x] = 1
    
    # 奇数をもった状態での移動
    if have_odd:
        if grid[y][x] % 2 == 1:
            ans_ls.append([y+1,x+1,previous_y+1,previous_x+1])
            have_odd = False
        else:
            ans_ls.append([y+1,x+1,previous_y+1,previous_x+1])
            previous_y,previous_x = y,x
    # 奇数を持っていない状態での移動
    else:
        if grid[y][x] % 2 == 1:
            previous_y,previous_x = y,x 
            have_odd = True
        else:
            pass

print(len(ans_ls))
for ans in ans_ls:
    print(*ans)

Measured memory_bytes: 103196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
ll k;
//ld ;
//string s;
// char c;

int main() {
  cin >> k;
  int series[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << series[k-1] << endl;
  return 0;
}

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

people = []
for _ in range(H):
    people.append(list(map(int, input().split())))

ans = 10 ** 20
for h in range(H):
    for w in range(W):
        tmp = 0
        for line in range(H):
            for row in range(W):
                tmp += min(abs(h - line), abs(w - row)) * people[line][row]
        ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 5604