akhauriyash/Code-Regression huggingface dataset:
from collections import deque

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

N = 3 * (n + 1)
adj = [[] for _ in range(N)]
for u, v in uv:
    for i in range(3):
        uu = u + i * n
        vv = v + ((i + 1) % 3) * n
        adj[uu].append(vv)

dq = deque([s])
d = [-1] * N
d[s] = 0
while dq:
    u = dq.popleft()
    for v in adj[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            dq.append(v)

ans = d[t] // 3
print(ans)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
const int MOD = (int)1e9 + 7;
int fac[N];

int powr(int n, int k){
  if(k == 0) return 1;
  int p = powr(n,k/2);
  p = (p * 1ll * p) % MOD;
  if(k % 2 == 1) p = (p * 1ll * n) % MOD;
  return p;
}

int pick(int n, int k){
  return (fac[n]*1ll*powr(fac[n-k],MOD-2)) % MOD;
}

int dp[N];
int cnt[N];

int main(){
  fastIO;
  fac[0]=1;
  for(int i = 1; i < N ; i ++ ) fac[i]=(fac[i-1]*1ll*i)%MOD;
  int n, x;
  cin >> n >> x;
  int s;
  vector<int> qi;
  for(int i = 1; i <=n; i ++ ){
    cin >> s;
    qi.push_back(s);
    cnt[s] ++ ;
  }
  sort(qi.begin(), qi.end());
  for(int i = N - 2; i >= 0 ; i -- ){
    cnt[i] += cnt[i + 1];
  }
  dp[x] = pick(n,cnt[x+1]);
  int nx;
  for(int i = x; i >= 1; i -- ){
    if(dp[i] == 0) continue;
    for(int t = 0 ; t < qi.size(); t ++ ){
      if(qi[t] > i) break;
      nx = i % qi[t];
      dp[nx] += (dp[i]*1ll*pick(n-cnt[i+1]-1,cnt[nx+1]-cnt[i+1]-1))%MOD;
      dp[nx] %= MOD;
    }
  }
  int ans = 0;
  for(int i = 0 ; i < qi[0]; i ++ ){
    ans += (dp[i] * 1ll * i) % MOD;
    ans %= MOD;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1280
import functools
import operator


if __name__ == "__main__":
    n, m, l = list(map(int, input().split()))

    inputs = []

    for _ in range(n + m):
        inputs.append(input())

    matrix_a = list(map(
        lambda input: list(map(int, input.split())),
        inputs[:n]
    ))
    matrix_b = list(map(
        lambda input: list(map(int, input.split())),
        inputs[n:n + m]
    ))

    matrix_c = []

    for row_a in matrix_a:
        row_c = []

        for col_b in list(zip(*matrix_b)):
            elem_c = functools.reduce(
                lambda acc, elem: acc + elem,
                map(operator.mul, row_a, col_b),
                0
            )

            row_c.append(elem_c)

        matrix_c.append(row_c)

    for row_c in matrix_c:
        print(' '.join(map(str, row_c)))


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

// AtCoder Beginner Contest 140
int main(){

    int n;
    cin >> n;

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

    int ans = 0;
    rep(i, n)ans += b[i];
    rep(i, n - 1)if(a[i] + 1 == a[i + 1])ans += c[a[i] - 1];

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var gtmax = 0; var gtmin = 0;
        var gmax = 0;
        var gmin = int.MaxValue;
        var count = 0;
        var imax = n * m / gcd(n, m);
        for (int i = 0; i < imax; i++)
        {
            var t = i % n;
            gmax = Max(gmax, a[t]);
            gmin = Min(gmin, a[t]);
            count++;
            if (count == m)
            {
                gtmax += gmax;
                gmax = 0;
                gtmin += gmin;
                gmin = int.MaxValue;
                count = 0;
            }
        }
        Console.WriteLine(gtmax - gtmin);
    }
    public static int gcd(int a, int b)
    {
        if (a < b) return gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}



Measured memory_bytes: 17924
#include <iostream>
using namespace std;
#define int long long

int solve(int n){
    if(n==1){
        return 1;
    }
    if(n==0)return 0;

    return 1+ 2*solve(n/2);
}
int32_t main() {
    int h;
    cin>>h;
    cout<<solve(h)<<endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int a, b, c; cin >> a >> b >> c;
	cout << min(b / a, c) << endl;

	return 0;
}


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

int main() {
  int A, B; // 5桁
  cin >> A >> B;
  
  int i;
  int count = 0;
  for (i = A; i <= B; i++){
    int At = i;
    
    int a1 = At / 10000;
    At %= 10000;
    int a2 = At / 1000;
    At %= 1000;
    int a3 = At / 100;
    At %= 100;
    int a4 = At / 10;
    At %= 10;
    int a5 = At;
    if (a1 == a5 && a2 == a4){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    int N = b - a ;

    System.out.println( N * ( N  + 1 ) / 2 - b  );
  }
}


Measured memory_bytes: 23252
//
//  main.c
//  ITP1_6_A
//
//  Created by k16031kk on 2018/05/24.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i=n-1; i>=0; i--) {
        scanf("%d", &a[i]);
    }
    for(int i=0; i<n; i++) {
        if(i) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
c=0
m=Array.new(n,0)
p=Array.new(n,0)
0.upto(n-1){|i|(i+1).upto(n-1){|j|
  m[i]+=1 if a[i]>a[j]; p[j]+=1 if a[i]<a[j];}}

s=m.inject(0){|sum,i|sum+i}
x=p.inject(0){|sum,i|sum+i}
puts (k*(k-1)/2*(s+x) + s*k)%(10**9+7)


Measured memory_bytes: 1916
N, Y = map(int, input().split())


def judge():
    for i in range(N + 1):
        for j in range(N + 1 - i):
            if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y:
                return "{} {} {}".format(i, j, N - i - j)
    return "-1 -1 -1"


print(judge())


Measured memory_bytes: 2940
import java.util.Scanner;public class Main{public static void main(String[]args){Scanner scan=new Scanner(System.in);
		//String str=scan.next();
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int ans=0;
		boolean bool=false;
		if(b/a>=c) {
			ans=c;
		}
		else {
			ans=b/a;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Int sum[305];
Int a[305];
Int dp[305][90005];
Int dp2[305][90005];


int main(){
    int N; cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        sum[i] = a[i];
        sum[i] += sum[i-1];
    }
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 90005; j++) {
            if (a[i] + j < 90005) {
                dp[i][a[i] + j] += dp[i-1][j];
                dp[i][a[i] + j] %= MOD;
            }
            dp[i][j] += dp[i-1][j]*2;
            dp[i][j] %= MOD;
        }
    }
    dp2[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < 90005; j++) {
            if (a[i] + j < 90005) {
                dp2[i][a[i] + j] += dp2[i-1][j];
                dp2[i][a[i] + j] %= MOD;
            }
            dp2[i][j] += dp2[i-1][j];
            dp2[i][j] %= MOD;
        }
    }
    Int cnt = 0;
    for (int j = 0; j < 90005; j++) {
        if (j >= sum[N]-j) {
            cnt += dp[N][j] * 3;
            cnt %= MOD;
        }
        if (j + j == sum[N]) {
            cnt -= dp2[N][j] * 3;
            cnt += MOD*3;
            cnt %= MOD;
        }
    }
    Int ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= 3;
        ans %= MOD;
    }
    ans = (ans - cnt + MOD) % MOD;
    cout << ans << endl;

}




Measured memory_bytes: 427520
#include<stdio.h>
typedef unsigned u;
u D[444][444];
int main()
{
	u q,i,j,k,x,y,a,b,c,r=9999;
	for(i=-1;++i<444;)
	for(j=-1;++j<444;)D[i][j]=r;
	scanf("%u%u%u",&q,&x,&y);
	for(D[0][0]=0;q--;)
	{
		scanf("%u%u%u",&a,&b,&c);
		for(i=444;i-->a;)for(j=444;j-->b;)
		{
			k=D[i-a][j-b]+c;
			if(D[i][j]>k)D[i][j]=k;
		}
	}
	for(i=x,j=y;i<444&&j<444;i+=x,j+=y)
	{
		if(D[i][j]<r)r=D[i][j];
	}
	printf(r>=9999?"-1\n":"%u\n",r);
	return 0;
}

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

int main()
{
	int n, k, h, ans = 0;
	cin >> n >> k;
	for (size_t i = 0; i < n; i++)
	{
		cin >> h;
		if (h>=k)
		{
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = []
for _ in range(m):
  b, c = map(int, input().split())
  d.append((b, c))
d.sort(key=lambda x: x[1], reverse=True)
l = 0
for bc in d:
  a.extend([bc[1] for _ in range(bc[0])])
  l += bc[0]
  if l > n: break
desc = sorted(a, reverse=True)
ans = sum(desc[:n])
print(ans)

Measured memory_bytes: 25932
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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

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


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {

    int n;
    cin >> n;
    int sum = 0;
    int i;
    for(i = 1; sum < n; i++){
        sum += i;
    }

    int over = sum - n;

    for(int j = 1; j < i; j++){
        if(j != over) cout << j << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();

		// 出力
		System.out.println(z + " " + x + " " + y);
	}
}

Measured memory_bytes: 21204
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	str := strings.Split(nextString(), "")
	q, _ := nextInt()

	for i := 0; i < q; i++ {
		cmd := nextString()
		a, _ := nextInt()
		b, _ := nextInt()

		// fmt.Println(cmd, a, b, str)

		if cmd == "print" {
			fmt.Println(strings.Join(str[a:(b+1)], ""))
		} else if cmd == "reverse" {
			part := make([]string, b+1-a)
			copy(part, str[a:(b+1)])
			// fmt.Println(part)
			for j := 0; j <= b-a; j++ {
				// fmt.Println(str[a+j], part[(b-a)-j])
				str[a+j] = part[(b-a)-j]
			}
		} else {
			p := strings.Split(nextString(), "")
			for j := a; j <= b; j++ {
				str[j] = p[j-a]
			}
		}
	}
}




Measured memory_bytes: 1656
#include <iostream>
#include <vector>
using namespace std;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
int main() {
	string s, t;
	cin >> s >> t;
	vector<ll> a[26];
	rep(i, s.size()) a[s[i] - 'a'].push_back(i);
	ll lap = 0, k = 0;
	bool ch = 0;
	for (auto c : t) {
		int m = c - 'a';
		if (a[m].empty()) {
			ch = 1;
			break;
		}
		auto itr = lower_bound(a[m].begin(), a[m].end(), k);
		if (itr == a[m].end()) {
			k = *a[m].begin() + 1;
			lap++;
		} else
			k = *itr + 1;
	}
	ll ans = s.size() * lap + k;
	if (ch)
		printf("-1\n");
	else
		printf("%lld\n", ans);
	return 0;
}


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

int n,pd[100002][3],k;
bool seen[100002][3];
vector<vector<int>> A;
inline void mmax(int &a,int b){
    a = max(a,b);
}
int dp(int id,int esc){
    if(id==n) return 0;
    if(seen[id][esc]) return pd[id][esc];
    for(int i=0;i<3;i++)
        if(esc!=i)
            mmax(pd[id][esc],dp(id+1,i)+A[id][i]);
    seen[id][esc] = true;
    return pd[id][esc];
}

int main(){
    cin >> n;
    A = vector<vector<int>> (n);

    for(auto &a:A){
        a = vector<int>(3);
        cin >> a[0] >> a[1] >> a[2];
    }
    cout << dp(0,-1) << '\n';
}


Measured memory_bytes: 14976
#include <iostream>

#define INF 1000000000

using namespace std;

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

    int ans = INF;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        int res = 0;
        while (A % 2 == 0) {
            res++;
            A /= 2;
        }
        ans = min(ans, res);
    }

    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i=0;i<N;++i){
    cin>>data.at(i);
  }
  int ans= 0;
  int sum= 0;
  while(sum+1<N){
    if(data.at(sum)==data.at(sum+1)){
      ans++;
      sum+= 2;
    }
    else{
      ++sum;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int state[10][10];
int fired[10][10];

void fire(int x, int y)
{
	int dx[] = { 0, 0, 1, 0, -1 };
	int dy[] = { 0, -1, 0, 1, 0 };
	for (int i = 0; i < 5; ++i)
	{
		int tx = x + dx[i];
		int ty = y + dy[i];
		if (0 <= tx && tx < 10
			&& 0 <= ty && ty < 10)
		{
			state[ty][tx] = state[ty][tx] ? 0 : 1;
		}
	}
	fired[y][x] = 1;
}
bool is_alloff()
{
	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			if (state[i][j])
				return false;
	return true;
}
void print_state(int s[10][10])
{
	for (int i = 0; i < 10; ++i)
	{
		for (int j = 0; j < 9; ++j)
			printf("%d ", s[i][j]);
		printf("%d\n", s[i][9]);
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int defState[10][10];
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
				int t;
				scanf("%d", &t);
				defState[i][j] = t;
			}
		}

		for (int subset = 0; subset < 1 << 10; ++subset)
		{
			memcpy(state, defState, sizeof(state));
			memset(fired, 0, sizeof(fired));

			for (int i = 0; i < 10; ++i)
				if (subset & 1 << i)
					fire(i, 0);

			for (int i = 1; i < 10; ++i)
			{
				for (int j = 0; j < 10; ++j)
				{
					if (state[i-1][j])
						fire(j, i);
				}
			}

			if (is_alloff())
				break;
		}
		print_state(fired);
	}

	return 0;
}

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

using namespace std;
const int mx = 1e5+10;

int tab[mx], dp[mx];
int main(){
   int n;
   scanf("%d",&n);

   for(int i=1; i<=n; i++)
      scanf("%d",&tab[i]);

   for(int i=2; i<=n; i++){
      dp[i] = min(dp[i-1]+abs(tab[i-1]-tab[i]), dp[max(i-2, 1)]+abs(tab[max(i-2, 1)] - tab[i]) );
      //printf("%d\n",dp[i]);
   }

   printf("%d\n",dp[n]);
   return 0;
}


Measured memory_bytes: 1024
/************************************************
 * Au: Hany01
 * Date: Feb 10th, 2019
 * Prob: yahoo2019_e
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 WoXiHuanNiA

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template <typename T> inline T read() {
	register T _, __; register char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int MAXN = 305, MOD = 998244353;

int fpm(int a, int b = MOD - 2) {
	int ans = 1;
	for ( ; b; b >>= 1, a = (LL)a * a % MOD)
		if (b & 1) ans = (LL)ans * a % MOD;
	return ans;
}

typedef bitset<MAXN> BS;

int n, m;
BS a[MAXN];

struct LinearBase {
	BS c[MAXN];
	int cnt;
	LinearBase() { cnt = 0; }
	void insert(BS a) {
		Fordown(i, n, 1)
			if (a.test(i)) {
				if (!c[i].test(i)) {
					c[i] = a;
					break;
				} else a ^= c[i];
			}
		if (!a.any()) ++ cnt;
	}
}B;

int main() {
#ifdef hany01
	freopen("yahoo2019_e.in", "r", stdin);
	freopen("yahoo2019_e.out", "w", stdout);
#endif

	n = read<int>(), m = read<int>();
	For(i, 1, n) {
		For(j, 1, m) a[i][j] = read<int>();
		B.insert(a[i]);
	}

	printf("%lld\n", (LL)(fpm(2, n) + MOD - fpm(2, B.cnt)) % MOD * fpm(2, m - 1) % MOD);

	return 0;
}

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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readH(in.readLine());
		solver.readW(in.readLine());
		solver.readN(in.readLine());
		// solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readH(String str) {
		H = Integer.parseInt(str);
	}

	public void readW(String str) {
		W = Integer.parseInt(str);
	}

	int H;
	int W;

	public void readN(String str) {
		N = Integer.parseInt(str);
		int ans = 0;
		int cntH = 0;
		int cntV = 0;
		for (int p = 0; p < N; ans++) {
			if (H - cntH > W - cntV) {
				p += (H - cntH);
				cntV++;
			} else {
				p += (W - cntV);
				cntH++;
			}
		}
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	string s1,s2;
	int cnt;
	int max;

	while(1){
		cin>>n;
		if(n==0) break;

		vector<pair<string,int> > v;

		for(int i1=0;i1<n;i1++){
			cin>>s1>>s2;
			v.push_back(make_pair(s1,1));
			v.push_back(make_pair(s2,0));
		}

		cnt=0;
		max=0;
		sort(v.begin(), v.end());
		for(int i1=0; i1<v.size();i1++){
			if(v[i1].second==1) cnt++;
			else if(v[i1].second==0) cnt--;

			if(max<cnt) max=cnt;
		}

		cout<<max<<endl;
	}
	return 0;
}

Measured memory_bytes: 2408
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

// vectorからindex番目の要素を削除する
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

struct Point
{
    int x;
    int y;
    	
        
    Point()
	{
	}
    Point(int i, int j)
	{
		x = i;
        y = j;
	}
};

struct {
    bool operator()(const Point &a ,const Point &b)const
    {   
		return a.y > b.y;
    }   
} greaterYSort;

struct {
    bool operator()(const Point &a ,const Point &b)const
    {   
		return a.x < b.x;
    }   
} XSort;


//c5モン
int main() { 
    int n;
    cin >> n;

    //赤
    vector <Point> aka(n);
    //青
    vector <Point> ao(n);

    vector <pint> pairs;

    int x,y;

    REP(i,n)
    {

        cin >> x >> y;
        //vector.at: vector.[i]と近いが、範囲外参照時にエラーを返してくれる
		aka.at(i) = Point(x,y);
    }
    REP(i,n)
    {
        cin >> x >> y;
        //vector.at: vector.[i]と近いが、範囲外参照時にエラーを返してくれる
		ao.at(i) = Point(x,y);
    }

    //青の中で最小のxが
    //赤のy座標の最も大きいもの

    //akaをx座標の小さい順にソート
    sort(aka.begin(), aka.end(), greaterYSort);

    //aoをy座標の大きい順にソート
    sort(ao.begin(), ao.end(), XSort);

#if DEBUG
    REP(i,n)
    {
        cout << aka[i].x << "," << aka[i].y << endl;
    }
        REP(i,n)
    {
        cout << ao[i].x << "," << ao[i].y << endl;
    }
#endif


    int aka_size = n;
    //青の中で最小のxが
    //赤のy座標の最も大きいもの
    int cnt = 0;
    REP(i,n)
    {
        REP(j,aka_size)
        {
            if(aka[j].x < ao[i].x && aka[j].y < ao[i].y)
            {
                //cout << aka[j].x <<  "," << aka[j].y << endl;
                //cout << ao[i].x <<  "," << ao[i].y << endl;
                ++cnt;
                //赤を削除
                remove(aka,j);
                --aka_size;
                break;
            }


        }
    }
    cout << cnt << endl;



    return 0;

}

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

using namespace std;
typedef long long ll;

int a[200050],b[200050];
int main()
{
   // ios::sync_with_stdio(false);
   // cin.tie(0);
   // cout.tie(0);
    int a,b,c;
    cin >> a >>b >>c;
    if(a==b&&c!=b||a==c&&c!=b||b==c&&a!=b)
        cout << "Yes\n";
    else
    cout << "No\n";
    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R'){
        cout << 3 << '\n';
        return 0;
    }
    if ((S[0] == 'R' && S[1] == 'R') || (S[1] == 'R' && S[2] == 'R')){
        cout << 2 << '\n';
        return 0;
    }
    if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R'){
        cout << 1 << '\n';
        return 0;
    }
    cout << 0 << '\n';
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int n;
    int count;
    int ans = 0;

    cin >> n;

    count = log10(n) + 1;

    if(count == 1){
        ans = n;
    }

    if(count == 2){
        ans = 9;
    }

    if(count == 3){
        int digit = n / 100;
        int amari = n % 100;
        ans = digit*100 - 99 + amari + 9;
    }

    if(count == 4){
        ans = 909;
    }
    if(count == 5){
        int digit = n / 10000;
        int amari = n % 10000;
        ans = digit*10000 - 9999 + amari + 909;
    } 

    if(count == 6){
        ans = 90909;
    }
    cout << ans;
    return 0;
}

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

tokei = []

for i in range(N-1):
    tokei.append(A[i+1]-A[i])
tokei.append(min(A[-1]-A[0],K-A[-1]+A[0]))
print(sum(tokei)-max(tokei))

Measured memory_bytes: 26436
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    ll sum = 0;
    sum += min(a, k);
    k -= min(a, k);

    if (k > 0) {
        k -= min(k, b);
        if (k > 0) {
            sum -= min(c, k);
        }
    }
    cout << sum << "\n";
}



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int[] counts = {0, 0, 0};

        for(int i = 0; i < N; i++) {
            int P = sc.nextInt();
            if (P <= A) {
                counts[0] += 1;
            } else if (P <= B) {
                counts[1] += 1;
            } else {
                counts[2] += 1;
            }
        }

        System.out.println(Math.min(Math.min(counts[0], counts[1]), counts[2]));
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    std::vector<int> wcnt;
    std::vector<int> ecnt;
    int w = 0;
    int e = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'W'){
            ++w;
        }
        if(s[i] == 'E'){
            ++e;
        }
        wcnt.push_back(w);
        ecnt.push_back(e);
    }

    int m = ecnt[n - 1];
    int first = ecnt[n - 1] - ecnt[0];
    int end = wcnt[n - 2];
    //std::cout<<"first:"<<first<<"end:"<<end<<std::endl;
    int res = std::min(first, end);
    for(int i = 1;i < n - 1;i++){
        int c = wcnt[i -1] + (m - ecnt[i]);
        //std::cout<<i<<":"<<c<<std::endl;
        if(c < res){
            res = c;
        }
    }
    std::cout<<res<<std::endl;
    return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin >> a >> b;
  for (int i=0;i<b.size();i++){
    cout << a[i] << b[i];
  }
  if (a.size()>b.size()){
    cout << a[a.size()-1];
  }
  cout << endl;
}

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

int main() {
    int n, m, d;
    scanf("%d %d %d", &n, &m, &d);
    int nSum = 0;
    for(int i=n; i<=m; i++) {
        if(i % d == 0) {
            nSum++;
        }
    }
    printf("%d\n", nSum);
    return 0;
}

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

long long n,s;
//inline long long f(long long b,long long n)
//{
//	if(n<b)
//		return n;
//	return f(b,n/b)+n%b;
//}
long long f(long long b,long long n)
{
	//cout<<n<<endl;
	long long sum=0;
	while(n)
	{
		sum+=n%b;
		n/=b;
	}
	return sum;
}
int main()
{
	scanf("%lld%lld",&n,&s);
	if(s==n)
		{
			printf("%lld\n",n+1);
			return 0;
		}
	if(s>n)
		{
			printf("-1\n");
			return 0;
		}
	for(long long i=2; i<=sqrt(n)+1; ++i)
		{
			if(f(i,n)==s)
				{
					printf("%lld\n",i);
					return 0;
				}
		}
	long long ji=n-s,ans=1e11;
	for(long long i=1; i*i<=ji; ++i)
		{
			if(ji%i==0)
				{
					long long b=ji/i+1;
					if(f(b,n)==s)
						ans=min(ans,b);
				}
		}
	if(ans==1e11)
		printf("-1\n");
	else
		printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,m; cin>>h>>w>>m;
    set<pair<int,int>> chk;
    vector<pair<int,int>> r_c(h),c_c(w);
    for(int i=0;i<h;i++) r_c[i].second=i;
    for(int i=0;i<w;i++) c_c[i].second=i;
    for(int i=0;i<m;i++){
        int h_t,w_t; cin>>h_t>>w_t;
        h_t--; w_t--;
        r_c[h_t].first++;
        c_c[w_t].first++;
        chk.insert({h_t,w_t});
    }
    int ma=0;
    sort(r_c.rbegin(),r_c.rend());
    sort(c_c.rbegin(),c_c.rend());
    for(auto i: r_c){
        for(auto j: c_c){
            int flag=0;
            if(chk.count({i.second,j.second})) flag=1;
            ma=max(ma,i.first+j.first-flag);
            if(!flag){
                break;
            }
        }
    }
    cout<<ma<<endl;
    return 0;
}



Measured memory_bytes: 21952
#include "bits/stdc++.h"
using namespace std;
typedef pair <int, int> pii;
int x[100010], y[100010];
const int inf = 1000000007;
int dp[100010];
const int mod = 1000000007;

bool cmp(pii a, pii b) {
	if(a.first == b.first) {
		return a.second > b.second;
	}
	return a.first < b.first;
}

int t[100010];

int query(int x) {
	x += 1;
	int ans = 0;
	for(int i = x; i > 0; i -= i & (-i)) {
		ans += t[i];
		ans %= mod;
	}
	return ans;
}
void update(int x, int val) {
	x += 1;
	for(int i = x; i <= 100003; i += i & (-i)) {
		t[i] += val;
		t[i] %= mod;
	}
}


int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &x[i]);
	}
	vector <int> v;
	for(int i = 1; i <= m; i++) {
		scanf("%d", &y[i]);
		v.push_back(y[i]);
	}
	sort(v.begin(), v.end());

	vector <pii> a;
	set <pii> s;
	for(int i = 1; i <= n; i++) {
		int id = upper_bound(v.begin(), v.end(), x[i]) - v.begin();
		int r = id < v.size() ? v[id] - x[i] : inf;
		int l = id > 0 ? x[i] - v[id - 1] : inf;
		if(l == inf || r == inf) continue;
		s.insert(pii(l, r));	
	}
	a = vector <pii> (s.begin(), s.end());
	sort(a.begin(), a.end(), cmp);

	vector <pii> u;
	for(int i = 0; i < a.size(); i++) {
		u.emplace_back(a[i].second, i);
	} 
	sort(u.begin(), u.end(), cmp);

	int ans = 1;
	for(int i = 0; i < u.size(); i++) {
		dp[i] = 1 + query(u[i].second);
		update(u[i].second, dp[i] % mod);
		ans += dp[i];
		ans %= mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8564
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

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




//overflowするときは1を返す
int is_mul_overflow(long long a, long long b) {
	float mul_log;

	if (a == 0 || b == 0) {
		return 0;
	}

	mul_log = log10f(a) + log10f(b);


	if (mul_log > 18.0) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {

	int X, Y;

	string ans;

	ans = "No";

	cin >> X >> Y;

	if (Y % 2 == 0 && Y >= X * 2 && Y <= X * 4) {
		ans = "Yes";
	}

	cout << ans << endl;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 3720
import java.util.*;


public class Main{
  
  public static void main(String[] args){
    ArrayList<Integer> array = new ArrayList<Integer>();
      
    
    Scanner scan = new Scanner(System.in);
    int val1 = scan.nextInt();
    int val2 = scan.nextInt();
    int val3 = scan.nextInt();
  	
    array.add(val1);
    array.add(val2);
    array.add(val3);
    
   
    int five=0;
    int seven=0;
    
    for (int i=0; i<array.size(); i++){
        if (array.get(i)==5){
            five++;
        }if(array.get(i)==7){
            seven++;
        }else{
            
        }   
    }
    
    if(five==2 && seven==1){
        System.out.println("YES");
    }else{
        System.out.println("NO");
    }
 
  }
  
 
}

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

int main() {
 long long n,a,b;
  cin>>n>>a>>b;
  long long  x=n/(a+b);
  long long y=n-x*(a+b);
  if(y>=a){cout<<a*x+a<<endl;
           
          }
  else{cout<<a*x+y<<endl;
 }
  
}


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

using namespace std;

template <class T> inline bool chmax(T &a, T b) { /* {{{ */
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int N, M, Q;
vector<int> A, B, C, D;
vector<int> v;
int ans;

void dfs(int idx) {
  if (idx == N) {
    int a = 0;
    for (int i = 0; i < Q; i++) {
      if (v[B[i]] - v[A[i]] == C[i]) {
        a += D[i];
      }
    }
    chmax(ans, a);
    return;
  }
  int last = idx == 0 ? 0 : v[idx - 1];
  for (int i = last; i < M; i++) {
    v[idx] = i;
    dfs(idx + 1);
  }
}

int main() {
  cin >> N >> M >> Q;
  A.resize(Q);
  B.resize(Q);
  C.resize(Q);
  D.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    A[i]--;
    B[i]--;
  }
  v.resize(N);
  dfs(0);
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

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

    vector<int> sortedA(A);
    sort(sortedA.begin(), sortedA.end());

    for (int i = 0; i < N; i++) {
        if (A[i] != sortedA[N - 1]) {
            cout << sortedA[N - 1] << endl;
        } else {
            cout << sortedA[N - 2] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    string s, t;
    cin >> N >> s >> t;
    int cnt = 0;

    for (int i = 1; i <= N; i++)
    {
        string before, after;
        for (int j = 0; j < i; j++)
        {
            before.push_back(s[N - 1 - j]);
            after.push_back(t[j]);
        }
        reverse(before.begin(), before.end());
        if (before == after)
        {
            cnt = i;
        }
    }
    cout << 2 * N - cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

import static java.lang.Integer.parseInt;

/**
 * Social
 */
public class Main {

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

		StringTokenizer st = new StringTokenizer(br.readLine());

		int N, K;
		N = parseInt(st.nextToken());
		K = parseInt(st.nextToken());

		int[][] bs = new int[N + 1][2];

		for (int i = 0; i < K; i++) {
			st = new StringTokenizer(br.readLine());
			int m = parseInt(st.nextToken());
			for (int j = 0; j < m; j++) {
				int b = parseInt(st.nextToken());
				bs[b][0] = i;
			}
		}

		int R = parseInt(br.readLine());

		for (int i = 0; i < R; i++) {
			st = new StringTokenizer(br.readLine());
			int p, q;
			p = parseInt(st.nextToken());
			q = parseInt(st.nextToken());
			if (bs[p][0] == bs[q][0]) {
				bs[p][1] = 1;
				bs[q][1] = 1;
			}
		}

		int count = 0;

		for (int i = 1; i <= N; i++) {
			if (bs[i][1] == 1) count++;
		}

		System.out.println(count);
	}
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong x;
    cin >> x;

    int t = 0;
    int ans;
    while (t * (t + 1) / 2 < x) {
        ++t;
    }

    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
from math import *
a, b, x = [float(a) for a in input().split()]
if x / a < a * b / 2:
    ans = atan2(a*b*b, 2*x)
else:
    ans = atan2(2*(a*a*b-x), a**3)

print(ans * 180 / pi)


Measured memory_bytes: 2940
from functools import reduce
N=int(input())
NS=[int(i) for i in input().split()]
Nminus = 0
Nzero = 0
minabs = 9223372036854775807
abssum = 0
for i in NS:
    if i < 0:
        Nminus += 1
    elif i == 0:
        Nzero += 1
    minabs = min(abs(i), minabs)
    abssum += abs(i)

if Nminus % 2 == 0 or Nzero > 0:
    print(abssum)
else:
    print(abssum - 2*minabs)


Measured memory_bytes: 14908
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
#define MAX_N 45
double PI = acos(-1.0);
double INF = 1e9;

int n,m;
P t[MAX_N];
double dp[MAX_N][MAX_N];

double calc(P s,P t){
  return imag(t*conj(s))/2.0;
}

double solve(int si){
  P a[MAX_N];
  for(int i=0;i<n;i++){
    a[i]=t[(i+si)%n];
  }

  for(int i=0;i<MAX_N;i++)
    for(int j=0;j<MAX_N;j++)
	dp[i][j]=-INF;
  dp[0][1]=0;

  double res=0;

  for(int i=0;i<n;i++){
    for(int j=1;j<m;j++){
      for(int k=i+1;k<n;k++){
	dp[k][j+1]=max(dp[k][j+1],dp[i][j]+calc(a[i],a[k]));
      }
    }
    res=max(res, dp[i][m]+calc(a[i],a[0]));
  }
  return res;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++){
      double d;
      cin>>d;
      t[i]=P(cos(d*2.0*PI),sin(d*2.0*PI));
    }
    double ans=0;
    for(int i=0;i<n;i++)ans=max(ans,solve(i));
    printf("%.6f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<long long> divisor(long long n) {
vector<long long> ret;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end()); // 昇順に並べる
return ret;
}

int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N,0);
    ll sum=0;
    for(ll i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    ;}
    vl Y=divisor(sum);
    ll ans=1;
    for(auto p: Y){
        vl B=A;
        for(ll i=0;i<N;i++){
            B[i]%=p;
        ;}
        ll Sum=0;
        for(ll i=0;i<N;i++){
            Sum+=B[i]; 
        ;}
        sort(B.begin(), B.end());
        ll Sum2=0;
        for(ll i=0;i<N;i++){
            Sum2+=B[i];
            if(Sum==p*(N-1-i))break;
        ;}
        if(Sum2<=K)ans=max(ans,p);
    ;}
    cout<<ans<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, T;
    cin >> N >> T;
    int A[N];
    int min_ary[N];
    int profit[N];
    int max_profit = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (i == 0) min_ary[0] = A[0];
        else min_ary[i] = min(min_ary[i - 1], A[i]);
        profit[i] = A[i] - min_ary[i];
        max_profit = max(max_profit, profit[i]);
    }
    for (int i = 0; i < N; i++) {
        if (profit[i] == max_profit) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int A,B,C,D;
    cin>>A>>B>>C>>D;
  if((A+B)>(C+D)){
  cout<< "Left" <<endl;
  }else if((A+B)<(C+D)){
  cout<< "Right" <<endl;
  }else{
  cout<< "Balanced" <<endl;
  }
}

Measured memory_bytes: 3644