akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cctype>
#include <vector>

using namespace std;

typedef long long lli;

string str;
int n;

main(){
  string in;
  while(getline(cin ,in)){
    str = "";
    for(int i=0;i<in.size();i++){
      if(isalpha(in[i])){
        str += toupper(in[i]);
      }
    }
    n = str.size();
    set<string> s;
    for(int i=0;i<n-2;i++){
      lli h1 = 0, h2 = 0, b = 1;
      int j = i;
      for(int k=0;k<2;k++){
        h1 *= 29;
        h1 += str[j] - 'A';
        h2 += b * (str[j] - 'A');
        b *= 29;
        j++;
      }
      for(;j<n;j++){
        h1 *= 29;
        h1 += str[j] - 'A';
        h2 += b * (str[j] - 'A');
        b *= 29;
        if(h1 == h2) s.insert(str.substr(i, j-i+1));
      }
    }
    vector<string> v;
    for(set<string>::iterator it=s.begin();it!=s.end();it++) v.push_back(*it);
    int m = v.size();
    bool f = true;
    vector<int> len;
    for(int i=0;i<m;i++) len.push_back(v[i].size());
    for(int i=0;i<m;i++){
      bool f2 = true;
      for(int j=0;j<m;j++){
        if(i == j) continue;
        if(len[i] < len[j] && v[i] == v[j].substr((len[j] - len[i]) / 2, len[i])){
          f2 = false;
          break;
        }
      }
      if(f2){
        if(!f) cout << " ";
        else f = false;
        cout << v[i];
      }
    }
    cout << endl;
  }
}

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

a = N
b = 0
B = []
if a == 0:
    B = [0]
while a:
    if a % 2 == 0:
        a, b = a//(-2) , 0
    else:
        a, b = a//(-2)+1, 1
    B.append(b)

B = B[::-1]
print(''.join([str(b) for b in B]))

Measured memory_bytes: 3064
// She is Pretty pretty!
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e3 + 100;
const int mod = 1e9 + 7;
int h, w;
char a[N][N];
int dp[N][N];
bool check(int x, int y){
    if(x <= h && y <= w && x >= 1 && y >= 1)return true;
    return false;
}
int main()
{
    cin >> h >> w;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(a[i][j] == '.'){
                if(check(i-1,j) && a[i-1][j] == '.'){
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] %= mod;
                }
                if(check(i,j-1) && a[i][j-1] == '.'){
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] %= mod;
                }
            }else dp[i][j] = 0;
        }
    }
    cout << dp[h][w];
    return 0;
}

Measured memory_bytes: 5632
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = sc.nextInt();
    Set<String> S = new HashSet<>();

    for (int i = 0; i < N; i++) {
      S.add(sc.next());
    }

    System.out.println(S.size());

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 62916
#include <stdio.h>

int main(void){
  int n,b[150],sum=0,a[150];
  scanf("%d",&n);
  for(int i=1;i<=n-1;i++){
    scanf("%d",&b[i]);
  }
  a[1]=b[1];
  for(int i=1;i<=n-2;i++){
    if(b[i]>=b[i+1]) a[i+1]=b[i+1];
    if(b[i]<b[i+1]) a[i+1]=b[i];
  }
  a[n]=b[n-1];
  for(int i=1;i<=n;i++){
    sum+=a[i];
  }
  printf("%d\n",sum);

  return 0;
    }

Measured memory_bytes: 1736
def four(n):
    if (int(n/4)):
        return four(int(n/4))+str(n%4)
    return str(n%4)

def check(A,bit,l,k):
    num=-1
    sum=0
    for i in range(N):
        if bit[i]==k:
            num+=1
            sum+=l[i]
    return abs(A-sum)+num*10

N,A,B,C=map(int,input().split())
l=[]
MP=10**5
for i in range(N):
    li=int(input())
    l.append(li)
for i in range(4**N):
    bit=four(i).zfill(N)
    if not("1" in bit):
        continue
    if not("2" in bit):
        continue
    if not("3" in bit):
        continue
    mp=check(A,bit,l,"1")+check(B,bit,l,"2")+check(C,bit,l,"3")
    if mp<=MP:
        MP=mp
print(MP)


Measured memory_bytes: 59352
n,m,c = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(1+n)]

count=0
for j in range(1,n+1):
  tmp=0
  for i in range(0,m):
    tmp+=e[j][i]*e[0][i]
#  print(tmp)
  if tmp+c>0:
    count+=1
    
print(count)



Measured memory_bytes: 3060
/////////////////////////////////////////
///       Please Give Me AC!!!!!      ///
/////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main() {
    const int dx[] = {1, -1, 0, 0};
    const int dy[] = {0, 0, 1, -1};

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

    vector<string> s(H);
    forin(s);

    bool IsOk = true;
    rep(i, H)rep(j, W){
        if(s[i][j] == '#'){
            bool IsNextOk = false;
            rep(k, 4){
                int y = i + dy[k];
                int x = j + dx[k];
                if(x >= 0 && x < W && y >= 0 && y < H){
                    if(s[y][x] == '#') IsNextOk = true;
                }
            }
            if(!IsNextOk) IsOk = false;
        }
    }
    if(IsOk) cout<< "Yes" << endl;
    else cout<< "No" << endl;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
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; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

LL modinv(LL a, LL m) {
  LL b = m, u = 1, v = 0;
  while (b) {
    LL t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0){
     u += m;
  }
  return u;
}

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}

void func() {
  LL X,Y;
  cin >> X;
  cin >> Y;
  LL A=0;
  if(X==1){
    A += 300000;
  }
  if(X==2){
    A += 200000;
  }
  if(X==3){
    A += 100000;
  }
  if(Y==1){
    A += 300000;
  }
  if(Y==2){
    A += 200000;
  }
  if(Y==3){
    A += 100000;
  }
  if(X==1 && Y==1){
    A += 400000;
  }
  cout << A;
  

  return;
}


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

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


signed main(){
    int K, A, B;
    cin >> K >> A >> B;
    int q = A/K;
    if((A <= q*K+K && q*K+K <= B) || (A <= q*K && q*K <= B)){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#[allow(unused_imports)]
use proconio::{
    fastout, input,
};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        mut p: [i32; n],
    }
    p.sort();
    println!("{}", p.iter().take(k).sum::<i32>());
}


Measured memory_bytes: 2144
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	ll N, M;
	cin >> N >> M;

	vl K(M), P(M);
	vvl S(M, (vector<ll>(N)));
	vector<bool> SW(N, false);

	rep(i, M) {
		cin >> K[i];
		rep(k, K[i]) {
			cin >> S[i][k];
		}
	}

	rep(i, M) {
		cin >> P[i];
	}



	ll count = 0;

	rep(i, pow(2,N)) {
		ll dst = i;
		rep(k, N) {
			if (dst % 2 == 1) SW[k] = true;
			else  SW[k] = false;
			dst = dst >> 1;
		}

		bool flg = true;

		rep(k, M) {
			ll lig = 0;
			rep(n, K[k]) {
				if (SW[S[k][n] - 1] == true)lig++;
			}
			if (lig % 2 != P[k]) flg = false;
		}

		if (flg == true)count++;


	}


	cout << count << endl;


	return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		for(int i=0; i<str.length(); i++){
			if(String.valueOf(str.charAt(i)).equals("B") && answer.length() != 0){
				answer = answer.substring(0, answer.length()-1);
			}else if(String.valueOf(str.charAt(i)).equals("0") || String.valueOf(str.charAt(i)).equals("1")){
				answer = answer + str.charAt(i);
			}
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 8276
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>


using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	map<string,int> x;
	string s;
	
	x["SUN"] = 7;
	x["MON"] = 6;
	x["TUE"] = 5;
	x["WED"] = 4;
	x["THU"] = 3;
	x["FRI"] = 2;
	x["SAT"] = 1;
	
	cin>>s;
	
	cout<<x[s]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int N,X;
    cin >> N >> X;
    int m[1010];
    for(int i = 0; i < N; ++i) cin >> m[i];
    int minel = *min_element(m, m+N);
    int cnt = 0;
    int donut = 0;
    for(int i = 0; i < N; ++i){
        cnt++;
        donut += m[i];
    }
    while(donut <= X){
        cnt++;
        donut += minel;
    }

    cnt--;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main(){

	int H,W;
	while(true)
	{
		cin >> H >> W;

		if(H+W == 0) break;

		for(int i=0;i<H;i++)
		{
			for(int k=0;k<W;k++)
			{
				if((i+k)%2 == 0) cout << "#";
				else cout << ".";
			}
			cout << "\n";
		}
		cout << "\n";

	}
	return 0;
}


Measured memory_bytes: 2996
N=int(input())
s=["".join(sorted(input())) for i in range(N)]
D=dict()
for st in s:
    if st in D:
        D[st]+=1
    else:
        D[st]=1
ans=0
for i in D:
    k=D[i]
    ans+=(k*(k-1))//2
print(ans)


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














int H, W, K, sx, sy, tx, ty;
string c[1010101];
int mi[1010101];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K >> sx >> sy >> tx >> ty;
	rep(y, 0, H) cin >> c[y];
	sx--; sy--; tx--; ty--;

	queue<int> que;
	rep(i, 0, 1010101) mi[i] = inf;

	que.push(sx * W + sy);
	mi[sx * W + sy] = 0;

	while (!que.empty()) {
		int q = que.front(); que.pop();

		int x = q / W;
		int y = q % W;

		if (x == tx && y == ty) {
			printf("%d\n", mi[q]);
			return;
		}

		rep(d, 0, 4) {
			int xx = x, yy = y;
			rep(k, 0, K) {
				xx += dx[d];
				yy += dy[d];

				if (xx < 0 || H <= xx || yy < 0 || W <= yy) break;
				if (c[xx][yy] == '@') break;
				
				int id = xx * W + yy;
				if (mi[id] <= mi[q]) break;
				if (mi[q] + 1 < mi[id]) {
					mi[id] = mi[q] + 1;
					que.push(id);
				}
			}
		}
	}

	printf("-1\n");
}







Measured memory_bytes: 40732
n, m = map(int, input().split(" "))
l = list(map(int, input().split(" ")))
l = sorted(l)

if n == 1:
	print(l[m-1] - l[0])
else:
	diff = []
	for i in range(m-1):
		diff.append(l[i+1] - l[i])
	diff = sorted(diff, reverse=True)
	print(sum(diff[n-1:]))

Measured memory_bytes: 13968
#include <iostream>
using namespace std;
 int dfs(int n, int s, int x){
    int sum=0;
    if(n==0 && s==0)
    return 1;
    if(n>0){
        for(int i=x; i<10; i++){
            if(s-i>=0)  sum+=dfs(n-1, s-i, i+1);
        }
    }
    return sum;
}
 int main(void){
    int n, s;
    while(cin >> n >> s){
        if(n==0 && s==0)
    break;
        cout << dfs(n, s, 0) << endl;
    }
    return 0;
}


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

int main(void) {
  int n, l; cin >> n >> l;
  vector<int> c;
  vector<int> t;
  for (int i=0; i<n; i++) {
    int tmpc, tmpt;
    cin >> tmpc >> tmpt;
    if (tmpt <= l) {
      c.push_back(tmpc);
      t.push_back(tmpt);
    }
  }
  
  if (c.size() == 0) {
    cout << "TLE" << endl;
    return 0;
  }
  
  int minc = 1001;
  for (int i=0; i<c.size(); i++) {
    if (c[i] < minc) minc = c[i];
  }
  
  cout << minc << endl;
  return 0;
}

Measured memory_bytes: 3612
fun main(args: Array<String>): Unit {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()

    val a = sc.asSequence().take(n).map(String::toLong).sorted().toMutableList()
    val bc = (1..m).map { sc.nextInt() to sc.nextLong() }.sortedByDescending { it.second }.toList()

    var i = 0
    var j = 0
    while (true) {
        if (j >= bc.count()) {
            break
        }
        var p = bc[j]
        for (k in 0 until p.first) {
            if (i >= a.count()) {
                break
            }
            if (p.second <= a[i]) {
                println(a.sum())
                return
            }
            a[i] = p.second
            i++
        }
        j++
    }
    println(a.sum())
}


Measured memory_bytes: 119172
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG


int main() {
  ll X, ans;
  cin >> X;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));

  ll count500, count5, rem_X;
  count500 = X / 500;
  rem_X = X % 500;

  count5 = rem_X / 5; 

  ans = count500 * 1000 + count5 * 5;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
from collections import deque
H,W = map(int, input().split())#H行　　W列
L=[]
kuro=0
siro=0

for i in range(H):
    a=list(input())
    L.append(a)
    for i in a:
        if i=='#':
            kuro+=1
        else:
            siro+=1
#print(kuro,siro)
#print(L)
q=deque([[1,1]])
move=[[1,0],[-1,0],[0,1],[0,-1]]
num=0
s=False
while q:
    #print(q)
    for i in range(len(q)):
        b=q.popleft()
        #print(b)
        if b==[H,W]:
            s=True
        #    print(num)
            print(H*W-kuro-num-1)
            break
        for m in move:
         #  print(m)
            if 1<=b[0]+m[0]<=H and 1<=b[1]+m[1]<=W and L[b[0]+m[0]-1][b[1]+m[1]-1]=='.':
                L[b[0]+m[0]-1][b[1]-1+m[1]]='#'
                q.append([b[0]+m[0],b[1]+m[1]])
        #print(L)
    num+=1
#print(L)
#print(num)
if not s:
    print('-1')

Measured memory_bytes: 3316
def main():

    import sys
    input = sys.stdin.readline

    n,m,l = map(int,input().split())
    Edge = [list(map(int,input().split())) for i in range(m)]
    q = int(input())
    Query = [list(map(int,input().split())) for i in range(q)]

    D2 = [[float("inf") for i in range(n)] for i in range(n)]
    for i in range(m):
        D2[Edge[i][0]-1][Edge[i][1]-1] = Edge[i][2]
        D2[Edge[i][1]-1][Edge[i][0]-1] = Edge[i][2]
    for i in range(n):
        D2[i][i] = 0

    def warshall_floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j],d[i][k] + d[k][j])
        return d

    D2 = warshall_floyd(D2)

    D = [[float("inf") for i in range(n)] for i in range(n)]
    for i in range(m):
        if Edge[i][2] <= l:
            D[Edge[i][0]-1][Edge[i][1]-1] = 1
            D[Edge[i][1]-1][Edge[i][0]-1] = 1
    for i in range(n):
        D[i][i] = 0
    for i in range(n):
        for j in range(n):
            if D2[i][j] <= l:
                D[i][j] = 1

    D = warshall_floyd(D)

    for query in Query:
        if D[query[0]-1][query[1]-1] != float('inf'):
            print(D[query[0]-1][query[1]-1]-1)
        else:
            print(-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 125020
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {

    //freopen(" E:\\workspace\\CLionProjects\\demo\\index.txt","r",stdin);
//    int x,y,divisor=1;
//
//    int maxDiver=100000;
//    vector<int >diverList;
//    diverList.push_back(1);
//    diverList.push_back(2);
//    for(int i=3;i<maxDiver;i++){
//        bool  flag=true;
//        for(int j=2;j<sqrt(i);j++){
//            if(i%j==0){
//                flag=false;
//                break;
//            }
//        }
//        if(flag)diverList.push_back(i);
//    }
//    int length=diverList.size();
    int x,y,divisor=1;
    cin>>x>>y;
    if(x>y)swap(x,y);
    for(int i=2;i<=x;){
        if(x%i==0&&y%i==0){
            divisor*=i;
            x=x/i;
            y=y/i;
        } else{
            i++;
        }
    }
    cout<<divisor<<endl;

    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <utility>
#include <list>
#include <algorithm>
#include <queue>
using namespace std;

using P = pair<int, int>;
using PP = pair<P, P>;

const int INF = (1 << 29);

// 最小値を計算するSegment tree
struct SegmentTree {
    const int DEFULT_VAL = INF;

    vector<int> dat;
    int end;

    SegmentTree(vector<int>& d) {
        int n = d.size();
        end = 1;
        while (end < n) end *= 2;

        dat.resize(2 * end - 1, DEFULT_VAL);
        
        for (int i = 0; i < d.size(); i++) {
            dat[i + end - 1] = d[i];
        }
        for (int i = end - 2; i >= 0; i--) {
            dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    void update(int idx, int a) {
        int id = idx + end - 1;
        dat[id] = a;
        while (id > 0) {
            id = (id - 1) / 2;
            dat[id] = min(dat[id * 2 + 1], dat[id * 2 + 2]);
        }
    }

    int query(int lb, int ub) {
        return query(lb, ub, 0, 0, end);
    }

    int query(int lb, int ub, int id, int node_lb, int node_ub) {
        if (node_ub <= lb || ub <= node_lb) { return DEFULT_VAL; }

        if (lb <= node_lb && node_ub <= ub) { return dat[id]; }
        else {
            int vl = query(lb, ub, id * 2 + 1, node_lb, (node_lb + node_ub) / 2),
                vr = query(lb, ub, id * 2 + 2, (node_lb + node_ub) / 2, node_ub);
            return min(vl, vr);
        }
    }
};

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

    static vector<int> p[2];
    static int rev[300000];
    p[0].resize(N); p[1].resize(N);

    for (int i = 0; i < N; i++) {
        cin >> p[i % 2][i];
        p[(i + 1) % 2][i] = INF;

        rev[p[i % 2][i]] = i;
    }

    static SegmentTree segtrees[2] = {
        SegmentTree(p[0]),
        SegmentTree(p[1])
    };

    vector<int> ans;
    priority_queue<PP, vector<PP>, greater<PP>> Q;
    auto temp = segtrees[0].query(0, N);
    Q.push({{temp, segtrees[1].query(rev[temp] + 1, N)},
            {0, N}});

    while (!Q.empty()) {
        auto pp = Q.top(); Q.pop();

        int X = pp.first.first;
        int Y = pp.first.second;
        P seg = pp.second;

        ans.push_back(X); ans.push_back(Y);

        auto push = [&](int L, int R) {
            if (R - L < 2) return;
            int a = segtrees[L % 2].query(L, R);
            int b = segtrees[(L + 1) % 2].query(rev[a] + 1, R);
            Q.push({{a, b}, {L, R}});
        };

        // [L, rX), [rX + 1, rY), [rY + 1, R)
        push(seg.first, rev[X]);
        push(rev[X] + 1, rev[Y]);
        push(rev[Y] + 1, seg.second);
    }

    for (int x : ans) {
        cout << x << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 9460
#include <iostream>
using namespace std;
int main(void){
    
    string s;
    cin >> s;
    
    if( s.at(0) == s.at(1) && s.at(1) == s.at(2) && s.at(0) == s.at(2)){
        cout << "No" << endl;
    }
    
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3036
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str = sc.next();
		int k  =sc.nextInt()-1;
		sc.close();
		char ch = str.charAt(k);
		for (int i=0;i<n;i++) {
			System.out.print((str.charAt(i)!=ch)?"*":str.charAt(i));
		}
		System.out.print("\n");
	}
}


Measured memory_bytes: 25044
import sys
def input(): return sys.stdin.readline().strip()

def main():
    H, W, M = map(int, input().split())
    bomb = set()
    yoko = [0] * W
    tate = [0] * H
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h-1, w-1))
        yoko[w - 1] += 1
        tate[h - 1] += 1

    idx_yoko = [(yoko[i], i) for i in range(W)]
    idx_tate = [(tate[i], i) for i in range(H)]
    idx_yoko.sort(reverse=True, key=lambda x: (x[0], x[1]))
    idx_tate.sort(reverse=True, key=lambda x: (x[0], x[1]))
    ans = 0

    yoko_bomb, idx_w = idx_yoko[0]
    tate_bomb_max = idx_tate[0][0]
    for tate_bomb, idx_h in idx_tate:
        if tate_bomb != tate_bomb_max: break
        if (idx_h, idx_w) not in bomb:
            print(yoko_bomb + tate_bomb)
            return

    tate_bomb, idx_h = idx_tate[0]
    yoko_bomb_max = idx_yoko[0][0]
    for yoko_bomb, idx_w in idx_yoko:
        if yoko_bomb != yoko_bomb_max: break
        if (idx_h, idx_w) not in bomb:
            print(yoko_bomb + tate_bomb)
            return

    print(yoko_bomb_max + tate_bomb_max - 1)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 174824
#include <stdio.h>

int N;
char S[310][310];

int check(int A) {
    for(int i=0; i<N; ++i) {
        int ii = (A+i)%N;
        for(int j=0; j<N; ++j) {
            if(S[ii][j]!=S[(A+j)%N][i]) {
                return 0;
            }
        }
    }
    return N;
}

int main() {
    scanf("%d", &N);
    for(int i=0; i<N; ++i) {
        scanf("%s", S[i]);
    }
    int count = 0;
    for(int A=0; A<N; ++A) {
        count += check(A);
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int n;
int main() {
	scanf("%d",&n);
	if(n == (n&(-n)) ) {
		puts("No");
		return 0;
	}
	printf("Yes\n1 2\n2 3\n3 %d\n%d %d\n%d %d\n",n+1,n+1,n+2,n+2,n+3);
	if(n == 3) return 0;
	int cur=4;
	for(;cur<=n-1;cur+=2) 
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",cur,cur+1,cur+1,n+1,n+1,n+cur,n+cur,n+cur+1);
	if(cur == n+1) return 0;
	for(int i=2;i<=n;++i)
		if((n^i^1)<=n) {
			if(i&1) printf("%d %d\n%d %d\n",n,i,n+n,(n^i^1)+n);
			else printf("%d %d\n%d %d\n",n,i+n,n+n,(n^i^1));
			return 0;
		}
	return 0;
}

Measured memory_bytes: 3764
while True:
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        a,b,c = map(int,input().split())
        if a == 100 or b == 100 or c == 100 or a+b >= 180 or a+b+c >= 240:
            print("A")
        elif a+b+c >= 210 or (a+b+c >= 150 and (a >= 80 or b >= 80)):
            print("B")
        else:
            print("C")


Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] sArray = sc.next().split("");
		double k = sc.nextDouble();
		for(int i = 0;i < sArray.length;i++) {
			double number = Double.parseDouble(sArray[i]);
			double count = Math.pow(number,5.0 * Math.pow(10, 15) );
			k -= count;
			if(k <= 0) {
				System.out.println((int)number);
				return;
			}
		}
	}
}

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

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

  int64_t sum = 0;
  for(int i=1;i<=N;i++){
    if(i%3!=0 && i%5!=0){
      sum += i;
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>

#define REP(i, n) for(int i=0;i<int(n);i++)
#define REPR(i, n) for(int i=int(n)-1;i>=0;i--)
#define FOR(i, a, b) for(int i=a;i<int(b);i++)
#define FORS(i, a, b, s) for(int i=a;(s>0&&i<int(b))||(s<0&&i>int(b));i+=s)

using namespace std;


int main() {
  
  int N, T, A;
  
  cin >> N >> T >> A;
  int X[N];
  REP(i,N){
    cin >> X[i];
  }
  
  double m = abs(T-0.006*X[0]-A);
  int mi = 0;
  REP(i,N){
    if(abs(T-0.006*X[i]-A)<m){
      mi = i;
      m = abs(T-0.006*X[i]-A);
    }
  }
  
  printf("%d\n", mi+1);
  return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

#define int long long

const ll MOD=1e9+7;
const ll INF=(1LL<<31)-1;
const double pi=acos(-1);
const double eps=1e-10;

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

class SquareDivision{
    private:
        const int BUCKET_SIZE=256;
        ll N, B;
        vector<ll> data;
        vector<ll> bucket_sum;
        vector<ll> bucket_add;

    public:
        void prepare(int n){
            B=(n+BUCKET_SIZE-1)/BUCKET_SIZE;
            N=B*BUCKET_SIZE;
            data.assign(N, 0);
            bucket_add.assign(B, 0);
            bucket_sum.assign(B, 0);
        }

        // [s, t)
        void add(int s, int t, int x){
            for(int k=0; k<B; k++){
                int l=k*BUCKET_SIZE, r=(k+1)*BUCKET_SIZE;

                if(r<=s || t<=l) continue;

                if(s<=l && r<=t){
                    bucket_add[k]+=x;
                }
                else{
                    for(int i=max(s, l); i<min(t, r); i++){
                        data[i]+=x;
                        bucket_sum[k]+=x;
                    }
                }
            }
        }

        int getsum(int s, int t){
            int sum=0;
            for(int k=0; k<B; k++){
                int l=k*BUCKET_SIZE, r=(k+1)*BUCKET_SIZE;

                if(r<=s || t<=l) continue;

                if(s<=l && r<=t){
                    sum+=bucket_sum[k]+bucket_add[k]*BUCKET_SIZE;
                }
                else{
                    for(int i=max(s, l); i<min(t, r); i++){
                        sum+=data[i]+bucket_add[k];
                    }
                }
            }
            return sum;
        }
};

signed main(){
    int n, q; cin>>n>>q;
    SquareDivision ans;
    ans.prepare(n);

    while(q--){
        int c; cin>>c;
        if(c==0){
            int s, t, x; cin>>s>>t>>x;
            ans.add(s, t+1, x);
        }
        else{
            int s, t; cin>>s>>t;
            cout << ans.getsum(s, t+1) << endl;
        }
    }
}


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

#define Max 1000
int top = 0;

int isEmpty( ) {
	return top == 0;
}

int isFull( ) {
	return top >= Max -1;
}

void push(int stack[Max], int value) {
	stack[++top]  = value;
}

int pop(int stack[Max]) {
	return stack[top--];
}

int main( ) {
	int N, i;
	int a, b;
	char A[Max];
	int stack[Max];
	int buff;

	while (scanf("%s", A) != EOF) {
		if (A[0] == '+') {
			a = pop(stack);
			b = pop(stack);
			push(stack, a + b);
		}
		else if (A[0] == '-') {
			a = pop(stack);
			b = pop(stack);
			push(stack, b - a);
		}
		else if (A[0] == '*') {
			a = pop(stack);
			b = pop(stack);
			push(stack, a * b);
		}
		else {
			push(stack, atoi(A));
		}
	}

	printf("%d\n", pop(stack));

	return 0;
}

Measured memory_bytes: 552
using System;

namespace A___Biscuit_Generator
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = double.Parse (input[0]);
            var b = int.Parse (input[1]);
            var t = int.Parse (input[2]);
            var x = Math.Floor (t / a);
            Console.WriteLine (x * b);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5+5;
int n;
ll a[N],f[N],g[N],ans=1e18;
stack<pii> stk;
int main(){
    cin>>n;
    for (int i=1; i<=n; i++) scanf("%lld",&a[i]);
    f[n]=0;
    for (int i=n-1; i>=1; i--){
        f[i]=f[i+1];
        ll tmp=a[i+1],now=a[i];
        while (a[i]>tmp){
            tmp*=4;
            if (stk.empty()) f[i]+=(n-i)*2;
            else{
                pii ts=stk.top(); stk.pop();
                f[i]+=(ts.first-i)*2;
                if (--ts.second) stk.push(ts);
            }
        }
        ll cnt=0;
        while (now*4<=tmp) now*=4,cnt++;
        if (cnt) stk.push({i,cnt});
    }
    while (!stk.empty()) stk.pop();
    for (int i=2; i<=n; i++){
        g[i]=g[i-1];
        ll tmp=a[i-1],now=a[i];
        while (tmp<a[i]){
            tmp*=4;
            if (stk.empty()) g[i]+=(i-1)*2;
            else{
                pii ts=stk.top(); stk.pop();
                g[i]+=(i-ts.first)*2;
                if (--ts.second) stk.push(ts);
            }
        }
        ll cnt=0;
        while (now*4<=tmp) now*=4,cnt++;
        if (cnt) stk.push({i,cnt});
    }
    for (int i=1; i<=n; i++)ans=min(ans,f[i]+g[i-1]+i-1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
n,m,l = map(int,raw_input().split(' '))
A = [ [0 for j in range(m)]for i in range(n)]
B = [ [0 for j in range(l)]for i in range(m)]
for i in range(n):
	A[i] = map(int,raw_input().split(' '))
for i in range(m):
	B[i] = map(int,raw_input().split(' '))	
for i in range(n):
	for j in range(l):
		sum = 0
		for k in range(m):
			sum += A[i][k]*B[k][j]
		print sum,
	print 

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

void CountingSort(vector<int> &A,vector<int> &B,int n,int k){
    vector<int> C(k+1);
    for(int i=0;i<k+1;i++){
        C[i]=0;        
    }
    for(int i=1;i<n+1;i++){
        C[A[i]]++;
    }
    for(int i=1;i<k+1;i++){
        C[i]=C[i-1]+C[i];
    }
    for(int i=n;i>0;i--){
        B[C[A[i]]]=A[i];
        C[A[i]]--;
    }
}

int main(){
    int n;
    cin>>n;
    vector<int> A(n+1),B(n+1);
    for(int i=0;i<n;i++){
        cin>>A[i+1];
    }

    CountingSort(A,B,n,10000);

    for(int i=1;i<n+1;i++){
        if(i-1) cout<<' ';
        cout<<B[i];
    }
    cout<<endl;
}


Measured memory_bytes: 18332
def main():
    s = list(input())
    count_list = [0] * 1
    index = 0
    for i in s:
        if i == "A" or i == "T" or i == "G" or i == "C":
            count_list[index] += 1
        else:
            index += 1
            count_list.append(0)
    
    ans = max(count_list)
    
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
typedef long long ll;
using namespace std;

ll k,p;
ll a[50];
int main() {
	cin>>k;
	rep(50)
		a[i]=49+k/50;
	p=0;
	rep(k%50){
		REP(50,j){
			if(j==p)a[j]+=50;
			else --a[j];
		}
		++p;
		p%=50;
	}
	cout<<50<<endl;
	rep(50)
		cout<<a[i]<<sp;
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BEcho {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        string s;
        cin >> s;
        if (N % 2 == 1) {
            cout << "No" << endl;
            return;
        }
        int len = N / 2;
        REP(i, len) {
            int j = i + len;
            if (s[i] != s[j]) {
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BEcho solver;
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;

void LIS(vector<int> vec) {
  deque<int> res{vec[0]};
  DUMP(res);
  FOR(i,1,vec.size()) {
    auto it = lower_bound(ALL(vec),vec[i]);
    if (it==vec.begin()) res.push_front(vec[i]);
    else res[it-vec.begin()-1]++;
    DUMP(res);
  }
  OUT(res.size());
}

int main() {
  // 使う色の最小数
  // LISで貪欲的に全部が使われるまで繰り返すのは？
  int N;cin>>N;
  vector<int> AS(N);
  REP(i,N) cin>>AS[i];

  deque<int> res{AS[0]};
  FOR(i,1,N) {
    auto it = lower_bound(ALL(res),AS[i]);
    if (it==res.begin()) {
      res.push_front(AS[i]);
    } else {
      res[it-res.begin()-1]=AS[i];
    }
  }
  OUT(res.size());

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
// #define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

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

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

string ans;
ll gcd(ll a, ll b){
  if(b == 0) return a;
  else return gcd(b, a % b);
}
void solve(){
  // main algorithm
  if (N == 1 || M == 1)
  {
    ans = "YES\n";
    return;
  }
  if(K % gcd(max(N, M), min(N, M))) {
    ans = "NO\n";
  }
  else {
    ans = "YES\n";
  }
  debug("gcd(N, M) = %d\n", gcd(max(N,M), min(N, M)));
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N >> M >> K;
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846264338327950L
int main(void)
{
int a, b, h, m;
scanf("%d%d%d%d", &a, &b, &h, &m);
 long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *b) * cosl(rad);

 printf("%20.20Lf\n", sqrtl(rsq));

 return 0;
}


Measured memory_bytes: 2528
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  Scanner sc;

  class Pair {
    int f;
    int s;

    Pair(int f_, int s_) {
      f = f_;
      s = s_;
    }
  }

  void run() {
    for ( ;; ) {
      int n = ni();

      if ( n == 0 ) {
        break;
      }

      HashMap<String, Pair> map = new HashMap<String, Pair>();

      map.put( "lu", new Pair( 1, 0 ) );
      map.put( "ru", new Pair( 0, 1 ) );
      map.put( "ld", new Pair( -1, 0 ) );
      map.put( "rd", new Pair( 0, -1 ) );

      int cnt = 0;
      int state = 0;
      Pair p = new Pair( 0, 0 );
      for ( int i = 0; i < n; ++i ) {
        String str = sc.next();
        Pair ofs = map.get( str );
        p.f += ofs.f;
        p.s += ofs.s;
        //debug(p.f, p.s);
        if ( p.f == p.s  && 1 - state == p.f) {
          ++cnt;
          state = 1 - state;
        }
      }

      System.out.println( cnt );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 26940
<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
for ($i=0; $i < $cnt; $i++) { 
    if ($i % 2 == 0 && $nums[$i] & 2 != 0) {
        $ans++;
    }
}
echo $ans;

Measured memory_bytes: 16124
#include <iostream>

using namespace std;

int main(void){
   
    long int X, Y;
    
    cin >> X >> Y;
    
    if(X % Y == 0){
        cout << -1 << endl;
        return 0;
    }
    int i = 2;
    while(1){
        if((X * i) % Y != 0){
            cout << X * i << endl;
            return 0;
        }
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int cnt = 0;

void selectionSort(vector<int> &a, int n)
{
  for (int i = 0; i < n; ++i)
  {
    int minj = i;
    for (int j = i; j < n; ++j)
    {
      if (a[j] < a[minj])
        minj = j;
    }
    if (i != minj)
      cnt++;
    swap(a[i], a[minj]);
  }
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a)
    cin >> e;
  selectionSort(a, n);
  for (int i = 0; i < n; ++i)
    cout << a[i] << (i + 1 == n ? "\n" : " ");
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int R,G,B,n;
  cin >> R >> G >>B >> n;
  int c = 0;
  int r = 0;
  while(R*r <= n) {
    int g = 0;
    while(R*r+G*g<=n) {
      if((n-R*r-G*g)%B==0){
        c += 1;
      }
      g += 1;
      
    }
    r+=1;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
N,h,u=map(int,input().split())
S = input()
kaigai=0
goukei=0
for i in range(0,N):
  if S[i]=='a' and goukei<h+u:
    print("Yes")
    goukei+=1
  elif S[i]=='b'and goukei<h+u and kaigai<u:
    print("Yes")
    goukei+=1
    kaigai+=1
  else:
    print("No")

Measured memory_bytes: 4016
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

def lcm(x, y):
    return x//gcd(x, y)*y

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

l = 1
for x in a:
    l = lcm(l, x)

ans = 0
for x in a:
    ans += l//x

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

Measured memory_bytes: 4084
N = int(input())
a = [int(n) for n in input().split()]

i = 0
c = 0
n = 1

while True:
    if i >= N:
        break
    while i < N and a[i] != n:
        c += 1
        i += 1
    if c == N:
        c = -1
        break
    i += 1
    n += 1

print(c)

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

int main(){
    int n,k;
    cin >> n >> k;
    map<int,int> ball;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        ball[a]++;
    }
    vector<int> num;
    for(auto p:ball){
        num.push_back(p.second);
    }
    sort(num.begin(), num.end());
    reverse(num.begin(), num.end());
    int ans=0;
    for(int i=0; i<num.size(); i++){
        if(i<k) continue;
        ans += num.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 13588