akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int c = scanner.nextInt();
        String s = scanner.next();
        int[] dpLeftToRight = new int[n];
        dpLeftToRight[0] = s.charAt(0) == 'x' ? 0 : 1;
        for (int i = 1; i < s.length(); ++i) {
            if (s.charAt(i) == 'x') {
                dpLeftToRight[i] = dpLeftToRight[i - 1];
            } else {
                if (i - c - 1 >= 0) {
                    dpLeftToRight[i] = Math.max(dpLeftToRight[i - 1], dpLeftToRight[i - c - 1] + 1);
                } else {
                    dpLeftToRight[i] = Math.max(dpLeftToRight[i - 1], 1);
                }
            }
        }
        if (dpLeftToRight[n - 1] > k || dpLeftToRight[n - 1] < k) {
            return;
        }

        int[] dpRightToLeft = new int[n];
        dpRightToLeft[n - 1] = s.charAt(n - 1) == 'x' ? k + 1 : k;
        for (int i = s.length() - 2; i >= 0; --i) {
            if (s.charAt(i) == 'x') {
                dpRightToLeft[i] = dpRightToLeft[i + 1];
            } else {
                if (i + c + 1 < n) {
                    dpRightToLeft[i] = Math.min(dpRightToLeft[i + 1], dpRightToLeft[i + c + 1] - 1);
                } else {
                    dpRightToLeft[i] = Math.min(dpRightToLeft[i + 1], k);
                }
            }
       //     System.out.println("dpRightToLeft[" + i + "]: " + dpRightToLeft[i]);
        }
        int[] earliestWorkDays = new int[n + 1];
        int[] latestWorkDays = new int[n + 1];


        for (int i = 0; i < n; ++i) {
            if (earliestWorkDays[dpLeftToRight[i]] == 0) {
                earliestWorkDays[dpLeftToRight[i]] = i + 1;
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            if (latestWorkDays[dpRightToLeft[i]] == 0) {
                latestWorkDays[dpRightToLeft[i]] = i + 1;
            }
        }
        for (int i = 0; i < n; ++i) {
            if (earliestWorkDays[dpLeftToRight[i]] == latestWorkDays[dpRightToLeft[i]] &&
                earliestWorkDays[dpLeftToRight[i]] == i + 1 && dpLeftToRight[i] == dpRightToLeft[i]
            ) {
                System.out.println(i + 1);
            }
        }
    }
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

// 最大公約数を計算( gcd.cpp 参照)
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

// 最小公倍数を計算
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  ll g = gcd(n, m);
  ll l = lcm(n, m);
  bool ok = true;
  for (ll i = 0; i < g; i++) {
    int nn = i * n / g;
    int mm = i * m / g;
    if (s.at(nn) == t.at(mm)) {
      continue;
    } else {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << l << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int ans = 1e9;
    for(int x = -100; x <= 100; x++){
        int cst = 0;
        for(int i=0;i<n;i++){
            cst += (a[i] - x) * (a[i] - x);
        }
        if(cst < ans) ans = cst;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, d, h;
	cin >> n >> h >> d;
	
	ll sumfac = 0, fac = 1;
	FOR(k,1,n+1) {
		fac = fac*k % MOD;
		sumfac = (sumfac + fac) % MOD;
	}
	
	vl dp(h+1);
	ll sum = dp[h] = 1;
	FORD(k,0,h) {
		dp[k] = (k > 0 ? sumfac : fac) * sum % MOD;
		sum += dp[k];
		if (k+d <= h) sum -= dp[k+d];
		sum %= MOD;
		if (sum < 0) sum += MOD;
	}
	cout << dp[0] << endl;

}



Measured memory_bytes: 8064
c=(0..18).map{[0]*19}
gets
p$<.sum{|a|a=(a.to_r*10**9).to_i
i,j=[2,5].map{|c|(0..17).find{a%c**-~_1>0}||18}
c[~i..].sum{_1[~j..].sum}+0*c[i][j]+=1}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	rep(i, n) cin >>a[i];
	
	int ct=0; ll sm = 0, amn = MD;
	rep(i, n){
		ct += a[i] <0;
		amn = min(amn, abs(a[i]));
		sm += abs(a[i]);
	}
	ll ans = ct%2? sm - amn*2: sm;

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


Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


a = IR(2)
for i in range(1, 4):
    if i not in a:
        print(i)
        exit()


Measured memory_bytes: 40048
#include<stdio.h>
int main(){
  int height,width,row,column,white;
  scanf("%d%d%d%d",&height,&width,&row,&column);
  white=height*width;
  white-=height*column;
  white-=(width-column)*row;
  printf("%d\n",white);
  return 0;
}


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

int main(void){
  int x, y, s, i, j;
  int tmp, higher;
  while(cin>>x>>y>>s){
    if(x == 0){
      break;
    }
    higher = 0;
    for(i=1;i<s;i++){
      for(j=i;j<s;j++){
        if(i * (100 + x) / 100 + (j * (100 + x) / 100) == s){
          tmp = i * (100 + y) / 100 + j * (100 + y) / 100;
          higher = max(higher, tmp);
        }
      }
    }
    cout<<higher<<endl;
  }
  return 0;
}


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

int a[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}; 
int k;

int main()
{
	cin >> k;
	cout << a[k-1] << endl;
	return 0;
}

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

int main()
{
    ll K;
    string S;
    cin >> S >> K;

    char firstNum = '1';

    for(ll i = 0; i < K; i++)
    {
        if(S[i] != '1')
        {
            firstNum = S[i];
            break;
        }
    }

    cout << firstNum << endl;
    return 0;
}

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

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 T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
    int movex = -(y2-y1), movey = x2-x1;
    cout << x2+movex << " " << y2+movey << " " << x1+movex << " " << y1+movey << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  int l = -1, r = INF;
  REP(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    chmax(l, a);
    chmin(r, b);
  }
  int ans = (l > r) ? 0 : r-l+1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt(), R = sc.nextInt();
		if(N >= 10) {
			pw.print(R);
		}else {
			pw.print(100*(10-N)+R);
		}
		pw.close();
	}
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d;
  //int mod=1000000;
  cin >> a >> b >> c >> d;
  long long v,w,x,y;
  v=a*c; w=a*d; x=b*c; y=b*d;
  long long ans;
  ans=max(max(max(v,w),x),y);
  cout<<ans<<endl;
  
}

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

int main() {
  int N, K, n;
  n = 0;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++) {
    cin >> h.at(i);
    if(h.at(i) >= K) {
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

//宣言部
#define MAX_RANGE 1000000
#define MIN_RANGE -1000000

//プロトタイプ宣言

int main(void){
    //宣言部
    int n = 0;
    long input_number = 0;
    long  sum_value = 0;
    long max_value = MIN_RANGE;
    long min_value = MAX_RANGE;
    //処理部
    scanf("%d",&n);
    
    while(n--){
        scanf("%ld",&input_number);
	sum_value= sum_value +input_number;
	if(max_value<input_number){
	    max_value = input_number;
	}
	if(min_value>input_number){
	    min_value = input_number;
	}
    } 
    printf("%ld %ld %ld\n",min_value,max_value,sum_value);
    return 0;
}






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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    string s,t; cin>>s>>t;
    int cnt = 0;
    for(i = 0; i < s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3920
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		//long[] a = new long[n];
		String s = "";
		BigDecimal bdb = new BigDecimal(String.valueOf(b));
		BigDecimal bda = new BigDecimal(String.valueOf(a));

		BigDecimal bd1 = bda.multiply(bdb).setScale(0, RoundingMode.DOWN);

		s = bd1.toPlainString();


		sc.close();
			System.out.println(s);


	}

}


Measured memory_bytes: 35928
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    as <- fmap concat . replicateM m $ do
        fmap read . words <$> getLine :: IO [Int]
    forM_ [1 .. n] $ \i -> do
        print $ length (filter (== i) as)

Measured memory_bytes: 892
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T>
constexpr bool in(T min, T max, T t)
{
    return t >= min && t <= max;
}

template <class T>
constexpr bool nin(T min, T max, T t)
{
    return !in(min, max, t);
}

template <class T>
void ninDebug(T min, T max, T t)
{
    using namespace std;
    if (nin(min, max, t))
    {
        cout << "ERROR" << endl;
    }
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int r;
    cin >> r;

    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String srg[]){
	Scanner scan = new Scanner(System.in);
    int a=scan.nextInt();
  	int b=scan.nextInt();
  	int c=scan.nextInt();
  	int count=0;
	for(int i=0;i<a;i++){
    
  	int d=scan.nextInt();
    int e=scan.nextInt();
     if(d>=b&&e>=c)count++;
    }
  
    System.out.println(count);
    scan.close();
}
}


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

template <typename stdinT>
void read_stdin(const size_t size, stdinT& array) {
   for (size_t i(0); i < size; ++i) {
      cin >> array[i];
   }
}

template <typename stdoutT>
void output_stdout(const size_t size, stdoutT& array) {
   for (size_t i(0); i < size; ++i) {
      cout << array[i] << endl;
   }
}

size_t inputA_size(1);
long long inputA[1];

size_t outputA_size(1);
long long outputA[1];

int main() {
   // read
   {
      read_stdin(inputA_size, inputA);
   }

   // process
   {
      outputA[0] = inputA[0] * inputA[0];
   }

   // output
   {
      output_stdout(outputA_size, outputA);
   }
   
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>

using namespace std;

int main() {
	double a, b,c,pi,s,l,h;
	cin >> a >> b >> c;
	pi = (c / 180) * M_PI;
	s = 0.5 * a * b * sin(pi);
	l = a + b + sqrt((a * a + b * b) - (2 * a * b * cos(pi)));
	h = 2 * s / a;
	cout << fixed<< setprecision(6)<<s<<endl;
	cout << fixed << setprecision(6) << l << endl;
	cout << fixed << setprecision(6) << h << endl;
	return 0;
}



Measured memory_bytes: 3528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u){
        cout<<a-1<<" "<<b<<endl;
    }
    else{
        cout<<a<<" "<<b-1<<endl;
    }
}

Measured memory_bytes: 256
import sys

inputs = sys.stdin
for line in inputs:
    a, op, b = line.strip().split()
    if op == "?":
        break
    elif op == "+":
        print int(a) + int(b)
    elif op == "-":
        print int(a) - int(b)
    elif op == "*":
        print int(a) * int(b)
    elif op == "/":
        print int(a) / int(b)

Measured memory_bytes: 6440
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int A,B;
	scanf("%d %d",&A,&B);
	int a_table[A];

	for(int i = 0; i < A; i++){
		scanf("%d",&a_table[i]);
	}

	int b_table[B];
	for(int i = 0; i < B; i++)scanf("%d",&b_table[i]);

	int maximum = 0,index;

	for(int base = 0; base < B; base++){
		index = 0;
		for(int down = base; down < B; down++){
			for(;index < A && b_table[down] != a_table[index]; index++);
			if(index == A)break;
			index++;
			maximum = max(maximum,down-base+1);
		}
	}

	printf("%d\n",maximum);

    return 0;
}

Measured memory_bytes: 2800
IDENTIFICATION DIVISION.
PROGRAM-ID. 159B.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 S          PIC X(100).
01 CNT        PIC 9(3).
01 E2         PIC 9(3).
01 S3         PIC 9(3).
01 P1         PIC 9(3).
01 P2         PIC 9(3).
01 OUT        PIC X(3).
*>
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT S.
  UNSTRING S DELIMITED BY ' '
      INTO S COUNT CNT. 
*>
  COMPUTE E2 = (CNT - 1) / 2.
  COMPUTE S3 = (CNT + 3) / 2.
*>
  MOVE 'Yes' TO OUT.
  MOVE   1 TO P1
  MOVE CNT TO P2
  PERFORM UNTIL (P1 >= P2) OR (OUT = 'No')
    IF (S(P1:1) NOT = S(P2:1))
      MOVE 'No' To OUT
    END-IF
    ADD      1 TO   P1
    SUBTRACT 1 FROM P2
  END-PERFORM.
*>
  MOVE 1  TO P1.
  MOVE E2 TO P2.
  PERFORM UNTIL (P1 >= P2) OR (OUT = 'No')
    IF (S(P1:1) NOT = S(P2:1))
      MOVE 'No' To OUT
    END-IF
    ADD      1 TO   P1
    SUBTRACT 1 FROM P2
  END-PERFORM.
*>
  MOVE S3  TO P1.
  MOVE CNT TO P2.
  PERFORM UNTIL (P1 >= P2) OR (OUT = 'No')
    IF (S(P1:1) NOT = S(P2:1))
      MOVE 'No' To OUT
    END-IF
    ADD      1 TO   P1
    SUBTRACT 1 FROM P2
  END-PERFORM.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 636
def main():
    def dfs(edge,s):
        use={s}
        q=[s]
        while q:
            v=q.pop()
            for w in edge[v]:
                if w in use:continue
                use.add(w)
                q.append(w)
        return use
    n,m,p,*t=map(int,open(0).read().split())
    edge=[[]for _ in range(n)]
    edge_rev=[[]for _ in range(n)]
    e=[]
    for a,b,c in zip(t[::3],t[1::3],t[2::3]):
        edge[a-1].append(b-1)
        edge_rev[b-1].append(a-1)
        e.append((a-1,b-1,p-c))
    use=dfs(edge,0)&dfs(edge_rev,n-1)
    e=[(a,b,c)for a,b,c in e if a in use and b in use]
    INF=10**18
    d=[0]+[INF]*(n-1)
    for _ in range(n):
        f=False
        for a,b,c in e:
            cost=d[a]+c
            if cost<d[b]:
                d[b]=cost
                f=True
        if not f:break
    else:
        print(-1)
        exit()
    print(max(-d[-1],0))
main()

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

r = [-1,-1,-1,0,1,1,1,0]
c = [-1,0,1,1,1,0,-1,-1]

GRID = []

for i in range(H):
    Si = input()
    GRID.append(Si)

for i in range(H):
    for j in range(W):
        if GRID[i][j]=='#':
            print('#',end='')
        else:
            cnt = 0
            for k in range(8):
                ni = i + r[k]
                nj = j + c[k]

                if ni < 0 or ni >= H or nj < 0 or nj >= W:
                    continue

                if GRID[ni][nj]=='#':
                    cnt+=1
                    
            print(cnt,end='')

    print('\n',end='')


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

using namespace std;

int main(){
    int n = 4;
    char s[n];
    scanf("%s", s);

    
    int count;
    bool f = true;
    for(int i = 0; i < n; i++){
        count = 1;
        for(int j = 0; j < n; j++){
            if(i != j && s[i] == s[j]){
                count++;
            }
        }
        if(count != 2){
            f = false;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <string.h>

using namespace std;

int x,y;
bool b = 1;

int main(){
    cin >> x;
    for(int i = x;; i++){
     	 b=1;
        for(int j = 2; j < i; j++){
            if(i % j == 0){
                b = 0;
                break;
            }
        }
        if(b){
            y = i;
            break;
        }
    }

    cout << y << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int M = sc.nextInt();
			int[] result = new int[N+1];
			for(int i = 0; i < N+1; i++){
				result[i] = 0;
			}
			for(int i = 0; i < M; i++){
				int temp = sc.nextInt();
				result[temp]++;
				temp = sc.nextInt();
				result[temp]++;
			}
			for(int i = 1; i < N+1; i++){
				System.out.println(result[i]);
			}
			
		}catch(Exception e){
			e.getMessage();
		}
	} 
}

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

long long floor_sum(long long n,long long m,long long a,long long b){
    long long ans=0;
    if (a>=m){
        ans+=(n-1)*n*(a/m)/2;
        a%=m;
    }
    if (b>=m){
        ans+=n*(b/m);
        b%=m;
    }
    long long y_max=(a*n+b)/m,x_max=y_max*m-b;
    if (y_max==0) return ans;
    ans+=(n-(x_max+a-1)/a)*y_max;
    ans+=floor_sum(y_max,a,m,(a-x_max%a)%a);
    return ans;
}

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

    for (;T--;){
        int N,M,A,B; cin >> N >> M >> A >> B;
        cout << floor_sum(N,M,A,B) << '\n';
    }
}

Measured memory_bytes: 3636
# 入力
n = gets.to_i
s = gets.chomp

# 文字を半分にする
a = (n/2)-1
mae = s.slice(0..a)
ushiro = s.slice(a+1..n-1)

# こたえ
if n == 1
  puts "No"
elsif mae == ushiro
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] heap = new int[n];
        for (int i = 0; i < n; i++) {
            heap[i] = in.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            System.out.println(printNode(heap, i));
        }
    }

    static String printNode(int[] heap, int i) {
        String parent;
        if (i > 1) {
            parent = "parent key = " + heap[i/2-1] + ", ";
        } else {
            parent = "";
        }

        if (i * 2 > heap.length) {
            return "node " + i + ": key = " + heap[i-1] + ", " + parent;
        } else if (i * 2 + 1 > heap.length) {
            return "node " + i + ": key = " + heap[i-1] + ", " + parent + "left key = " + heap[i*2-1] + ", ";
        } else {
            return "node " + i + ": key = " + heap[i-1] + ", " + parent + "left key = " + heap[i*2-1] + ", "
                    + "right key = " + heap[i*2] + ", ";
        }
    }
}



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

int main() {
  int a;
  cin>>a;
  int answer=10000;
  int k;
  int p=0;
  for(int i=0;i<a;i++){
    cin>>k;
    while(k%2 ==0){
      k=k/2;
      p+=1;
    }
    if(p<answer){
      answer=p;
    }
    p=0;
  }
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#define fr first
#define sc second
#define INF 100000001
using namespace std;
bitset<INF> Prime;
int main(){
  Prime[1]=true;
  for(int i=3;i<=sqrt(INF);i += 2){
    if(!Prime[i]){
      for(int j=3;i*j<INF;j += 2){
        Prime[j*i] = true;
      }
    }
  }
  int n,a,cnt=0;
  cin >> n;
  while(n--){
    cin >> a;
    if(a == 2) cnt++;
    else if(a % 2 == 1 && !Prime[a]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 13372
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int d,t,s;
    cin>>d>>t>>s;
    puts(d<=t*s?"Yes":"No");
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
    
        int a,b=0;
        while(true){
            a = sc.nextInt();
            if(a == 0)  break;
            System.out.println("Case " + (++b) + ": "+a);
        }
        

    
        sc.close();

    }
}





Measured memory_bytes: 41208
S = str(input())

out = dict()
for s in S:
	if s in list(out.keys()):
		out[s] += 1
	else:
		out[s] = 1

if (len(list(out.keys())) == 2) and ([out[key] for key in out.keys()] == [2,2]):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
import sys
from collections import deque
import copy

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    count = nums[0]
    for i in range(1, len(nums)):
        count *= nums[i]
    count -= 1
    ret = 0
    for n in nums:
        ret += count % n
    return ret


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3820
import Control.Monad
import Data.List as L
import Data.IntMap as M

primes :: Integral a => [a]
primes = takeWhile (<31623) $ L.map fromIntegral ([2, 3] ++ primes' :: [Int])
    where
      primes' = 5 : sieve [] primes' 7
      sieve divs (x : xs) n = ps ++ sieve (divs ++ [x]) xs (x * x)
          where
            isPrime m = and [rem m x /= 0 | x <- divs]
            ps = L.filter isPrime ns
            ns = [y + z | y <- [n, n + 6 .. x * x - 2], z <- [0, 4]]

fac :: [Integer]->M.IntMap Integer->Integer->M.IntMap Integer
fac _ m 1 = m
fac [] m n = M.insert (fromIntegral n) 1 m
fac pa@(p:pr) m n
    |mod n (fromIntegral p)==0=fac pa (M.insertWith(+) (fromIntegral p) 1 m) (div n (fromIntegral p))
    |otherwise =fac pr m n
 
invmod p g = invmod' 1 0 p 0 1 g
    where invmod' px py pgcd x y gcd
            | m==0 = mod (x+g) g
            | True = invmod' x y gcd (px - (d*x)) (py - (d*y)) m
            where
                m = mod pgcd gcd
                d = div pgcd gcd
 
divmod a b p = mod (a * invmod b p) p
 
cmbmod n k p = L.foldl' (\a i->divmod (mod (a*(n-i+1)) p) i p) 1 [1..k]
 
sol 1 _ = 1
sol _ 1 = 1
sol n m = L.foldl' (\a b -> (a * cmbmod (b+n-1) b 1000000007) `mod` 1000000007) 1 fm
    where fm = elems $ fac primes M.empty m

main=do
    (n:m:_)<-L.map read . words<$>getLine::IO[Integer]
    print $ sol n m

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
 int N;
 cin>>N;
 int sum=0;
 int x=N;
 while(x>0){
     sum+=x%10;
     x/=10;
 }
 if(N%sum==0){cout<<"Yes"<<endl;}
 else{cout<<"No"<<endl;}
 return 0;}

Measured memory_bytes: 256
#if 0
dp[i][j] = min( dp[i???1][j] , dp[i][j???c[i]]+1 )
					||
dp[i] = min ( dp[j] , dp[j-c[i]]+1 )					
#endif

#include <iostream>  
using namespace std;  
 
  
const int MAX_NUM = 50010;  
const int MAX_WEIGHT = 50000+20;  

   
int c[MAX_NUM];  
 
int dp[MAX_WEIGHT];  
  

void Solve( int n, int m )  
{     
	for (int i=0; i<m; i++ )  
	{  
		for (int j=c[i]; j<=n; j++)  
		{   
			dp[j] = min(dp[j],dp[j-c[i]]+1);      	         
		}  
	}  
	cout << dp[n] << endl;  
}  

int main()  
{    
	int n, m;  
	cin >> n >> m;        
	for (int i=0; i<m; i++ )  
	{  
		cin >> c[i];  
	}  
	for (int i=1; i<=n; i++)
	{
		dp[i] = 50000+10;
	}
	Solve( n, m );  
 
	return 0;  
}  

Measured memory_bytes: 3248
package main

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

var sc = bufio.NewScanner(os.Stdin)

// var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

type K struct {
	Price int
	Count int
}

type Ks []K

func (ks Ks) Len() int {
	return len(ks)
}
func (ks Ks) Less(i, j int) bool {
	return ks[i].Price < ks[j].Price
}
func (ks Ks) Swap(i, j int) {
	ks[i], ks[j] = ks[j], ks[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	//	defer out.Flush()   // !!!!coution!!!! you must use Fprint(out, ) not Print()

	N := nextInt()
	M := nextInt()
	ks := make([]K, N)
	for i := 0; i < N; i++ {
		ks[i].Price = nextInt()
		ks[i].Count = nextInt()
	}
	// sort.Slice(ks, func(i, j int) bool {
	// 	return ks[i].Price < ks[j].Price
	// })
	sort.Sort(Ks(ks))

	var res int64 = 0
	rest := M
	for i := 0; i < N; i++ {
		if ks[i].Count < rest {
			res += int64(ks[i].Price) * int64(ks[i].Count)
			rest -= ks[i].Count
		} else {
			res += int64(ks[i].Price) * int64(rest)
			rest -= rest
		}
		if rest == 0 {
			break
		}
	}
	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,s;
    cin>>n>>k;
    vector<ll>vc;
    map<ll,ll>mp;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        if(mp[a]==0)
        {
            vc.push_back(a);
            mp[a]=mp[a]+b;
        }
        else if(mp[a]!=0)
        {
            mp[a]=mp[a]+b;
        }
    }
    sort(vc.begin(),vc.end());
    i=0;
    s=0;
    while(s<k)
    {
        l=vc[i];
        j=mp[l];
        s+=j;
        i++;
    }
    cout<<l<<endl;
    return 0;

}


Measured memory_bytes: 4728
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int main(){
  ll N; cin>>N;
  umap<string,ll> mp;
  ll ans = 0;
  REP(count,N){
    string s; cin>>s;
    ++mp[s];
    if(mp[s]==1){++ans;}
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 17616
import sys

line_num = int(sys.stdin.readline().rstrip())
maxv = -2000000000
minv = int(sys.stdin.readline().rstrip())

for i in range(1, line_num):
    rt = int(sys.stdin.readline())
    if rt - minv > maxv:
        maxv = rt - minv
    if rt < minv:
        minv = rt

print(maxv)

Measured memory_bytes: 7668
#include <iostream>
using namespace std;
int main () {
  int n;
  float t, a;
  cin >> n;
  cin >> t >> a;
  float min = -1;
  int ans = -1;
  for (int i = 0; i < n; i++) {
    float sub;
    cin >> sub;
    sub = t - 0.006 * sub;
    float subsub = -1;
    if (a - sub > 0) {
      subsub = a - sub;
    } 
    else {
     subsub = sub - a;   
    }
    if (subsub < min || min < 0) {
      min = subsub;
      ans = i;  
    }
  }  
  cout << ans + 1 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int r;
  cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 3604
def da_generate(h,w,a):
    da = [[0]*w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1,w):
        da[0][i] = da[0][i-1]+a[0][i]
    for i in range(1,h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i-1][j]+cnt_w
    return da

def da_calc(da,p,q,x,y):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y]-da[x][q-1]
    if q == 0:
        return da[x][y]-da[p-1][y]
    return da[x][y]-da[p-1][y]-da[x][q-1]+da[p-1][q-1]

n , k = map(int,input().split())
mototen = []
atuten = []
zax = []
zay = []
for i in range(n):
    x , y = map(int,input().split())
    mototen.append((x,y))
    zax.append(x)
    zay.append(y)
zax.sort()
zay.sort()

a = [[0 for i in range(len(zay))] for j in range(len(zax))]

for x , y in mototen:
    atx = zax.index(x)
    aty = zay.index(y)
    a[atx][aty] += 1
b = da_generate(len(zax),len(zay),a)
ans = float("inf")
for p in range(len(zax)-1):
    for q in range(len(zay)-1):
        for x in range(p+1,len(zax)):
            for y in range(q+1,len(zax)):
                kar = da_calc(b,p,q,x,y)
                if kar >= k:
                    men = (zax[x]-zax[p])*(zay[y]-zay[q])
                    ans = min(ans,men)
print(ans)

Measured memory_bytes: 9324
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


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

    // エラトステネス
    // 0からmxまでの素数を割り出す
    int mx = 100100;
    vector<bool> is_prime(mx, true);   // すべて素数と初期化
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < mx; i++) {
        // 約数にiをもつ数値をfalseにしていく
        if (!is_prime[i]) continue;
        for (int j = i*2; j < mx; j += i) {
            is_prime[j] = false;
        }
    }

    int cnt = 0;
    rep(i,55556) {
        if (cnt == n) break;
        if (is_prime[i] && (i-1)%5==0) {
            cout << i << " ";
            cnt++;
        }
    }
    cout << endl;
    return 0;
}


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

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

    int ans = (a - 1) * (b - 1);

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


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

typedef long long ll;

vector<int> pre,in,post;
int n,pos;

void solve(int l,int r){
    if(l>=r)return;
    int root=pre[pos++];
    int m=distance(in.begin(),find(in.begin(),in.end(),root));
    solve(l,m);
    solve(m+1,r);
    post.push_back(root);
}

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

    cin >> n;
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        pre.push_back(k);
    }
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        in.push_back(k);
    }
    solve(0,pre.size());
    for(int i=0;i<n;i++){
        if(i)cout << " ";
        cout << post[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3220
from bisect import *
n = int(input())
a = sorted(list(map(int,input().split())))
b = list(map(int,input().split()))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
    l = bisect_left(a, b[i])
    r = n - bisect_right(c,b[i])
    ans += l*r
print(ans)

Measured memory_bytes: 23744
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

#define MH 8
#define MW 8

int H, W, C;
int P[MH][MW];
bool input() {
    cin >> H >> W >> C;
    if (H == 0 && W == 0 && C == 0) return false;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> P[i][j];
        }
    }
    return true;
}

const int dy[] = {0, 1, 0, -1},
          dx[] = {1, 0, -1, 0};
int Count() {
    if (P[0][0] != C) return 0;
    bool used[H][W]; memset(used, 0, sizeof(used));
    used[0][0] = true;
    queue< pair<int, int> > Q;
    Q.push(make_pair(0, 0));
    int Ret = 0;
    while (!Q.empty()) {
        pair<int, int> next = Q.front(); Q.pop();
        Ret++;
        int y = next.first,
            x = next.second;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i],
                nx = x + dx[i];
            if (ny < 0 || ny >= H) continue;
            if (nx < 0 || nx >= W) continue;
            if (used[ny][nx]) continue;
            if (P[ny][nx] != C) continue;
            Q.push(make_pair(ny, nx));
            used[ny][nx] = true;
        }
    }
    return Ret;
}

void Change(int color) {
    bool used[H][W]; memset(used, 0, sizeof(used));
    int pcolor = P[0][0];
    used[0][0] = true;
    queue< pair<int, int> > Q;
    P[0][0] = color;
    Q.push(make_pair(0, 0));
    while (!Q.empty()) {
        pair<int, int> next = Q.front(); Q.pop();
        int y = next.first,
            x = next.second;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i],
                nx = x + dx[i];
            if (ny < 0 || ny >= H) continue;
            if (nx < 0 || nx >= W) continue;
            if (used[ny][nx]) continue;
            if (P[ny][nx] != pcolor) continue;
            P[ny][nx] = color;
            Q.push(make_pair(ny, nx));
            used[ny][nx] = true;
        }
    }
}

void dump() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cerr << setw(3) << P[i][j];
        }
        cerr << endl;
    }
    cerr << endl;
}

int dfs(int R) {
    if (R == 0) {
        return Count();
    }
    int P1[MH][MW];
    int Max = 0;
    for (int color = 1; color <= 6; color++) {
        memcpy(P1, P, sizeof(P));
        Change(color);
        Max = max(Max, dfs(R - 1));
        memcpy(P, P1, sizeof(P));
    }
    return Max;
}

void solve() {
    cout << dfs(5) << endl;
}

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

Measured memory_bytes: 1208
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	long long N, K;
	cin >> N >> K;
	N %= K;
	cout << min(N, K - N) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char ch;
  while(1){
    scanf("%c",&ch);
    if('a'<=ch && ch<='z')ch-=32;
    else if('A'<=ch && ch<='Z')ch+=32;
    printf("%c",ch);
    if(ch=='\n')
break;
  }
  return 0;
}



Measured memory_bytes: 2112
/*
                                        //     //     //\\\\\\\\\
                                        \\    //      \\        \\
                                        //   //       //         \\
                                        \\  //        \\          \\
                                        // //         //           \\
                                        \\//          \\            \\       
                                        //\\          //            //
                                        \\ \\         \\           //
                                        //  \\        //          //
                                        \\   \\       \\         //
                                        //    \\      //        //
                                        \\     \\     \\/////////
*/

#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vint vector <int>
#define vll vector <long long int>
#define endl cout<<'\n'
#define fre(i,l,n) for(long long int i=l;i<n;++i)
#define fr(i,l,n) for(long long int i=l;i<=n;i++)
#define rfre(i,n,l) for(long long int i=n-1;i>=l;i--)
#define rfr(i,n,l) for(long long int i=n;i>=l;--i)
#define tab '\t'
#define debug cout<<'*';
#define s(a) cin>>a
#define p(a) cout<<a
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef pair<int,pair<int,int> > tii;
typedef vector<int> vec;
typedef vector<long long> vecll;
typedef vector<pair<int,int> > vec_pii;
typedef vector<pair<long long int,long long int> > vec_pll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<pair<int,int> > > vvpii;
typedef vector<vector<pair<ll,ll> > > vvpll;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define Pi 3.14159265358979
#define gcd(a,b) __gcd(a,b)
#define sf(n) scanf("%lld",&(n))
#define pf(n) printf("%lld\n",(n))
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define w(t) while(t--)
#define flt(a) cout<<fixed<<setprecision(a)
#define cntSetBits(n) __builtin_popcountll(n)
/*****************************
*****************************/

#define modi 998244353


ll dp[3005][3005];


void solve()
{
    ll a,b,c,d;
    s(a);s(b);s(c);s(d);
    dp[a][b] = 1;
    fr(i,1,c)
    {
        fr(j,1,d)
        {
            dp[i][j] = (dp[i][j] % modi + (i%modi * dp[i][j-1]%modi)%modi)%modi;
            dp[i][j] = (dp[i][j] % modi + (j%modi * dp[i-1][j]%modi)%modi)%modi;
            dp[i][j] = (dp[i][j] % modi - ((i-1)%modi * (j-1)%modi * dp[i-1][j-1]%modi)%modi + modi)%modi;
        }
    }
    p(dp[c][d]);endl;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t=1;
    // s(t);
    w(t)
    {
        solve();
    }
    return 0;
}









Measured memory_bytes: 73908
fn circle() -> Result<u32, &'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|_| "input error")?;
    let r = input.trim_right().parse::<u32>()
        .map_err(|_| "parse error")?;

    Ok(r * r)
}

fn main() {
    println!("{}", circle().unwrap());
}


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

class Main {

     public static void main(String []args){
        FastReader sc = new FastReader();
        
        int n = sc.nextInt(), k = sc.nextInt();
        int [] heights = new int [n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }
        int [] dp = new int [n];
        
        for (int i = 1; i < n; i++) {
            dp[i] = dp[i - 1] + Math.abs(heights[i] - heights[i - 1]);
            for (int j = i - 2; j >= Math.max(0, i - k); j--) {
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(heights[i] - heights[j]));
            }
        }
        
        System.out.println(dp[n - 1]);
     }
     
     static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  
}

Measured memory_bytes: 39400
#include<stdio.h>
int main(){
	int a[10000],i,j,x;
	
	for(i=0;i<3;i++){
	scanf("%d",&a[i]);
	}
	
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				x=a[i];
				a[i]=a[j];
				a[j]=x;
			}
		}
	}
	
	for(i=0;i<3;i++){
	printf("%d",a[i]);
		if(i<2){
			printf(" ");
		}
	}
	printf("\n");
	
	
	
	return 0;
}



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

int main(){

	int K,keta;
	char N[110];
	scanf("%s",N);
	scanf("%d",&K);
	keta = strlen(N);
	
	int dp[keta+1][K+1][2];
	
	for(int i=0;i<keta+1;i++){
		for(int j=0;j<K+1;j++){
			dp[i][j][0] = 0;
			dp[i][j][1] = 0;
		}
	}
	dp[0][0][0] = 1;
	
	for(int i=0;i<keta;i++){
		int nd = N[i]-'0';
		for(int j=0;j<K+1;j++){
			for(int k=0;k<2;k++){
				for(int d=0;d<10;d++){
					int ni=i+1,nj=j,nk=k;
					if( d!=0 ) nj++;
					if( nj>K ) continue;
					if( k==0 ){
						if( d>nd ) continue;
						if( d<nd ) nk=1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	
	printf("%d",dp[keta][K][1]+dp[keta][K][0]);
	return 0;
}


Measured memory_bytes: 128