akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N,X,Y;
    cin>>N>>X>>Y;
    vector<ll> a(N);
    rep(i,0,N) cin>>a[i];

    if (N==1)
        cout<<abs(a[0]-Y)<<endl;
    else
        cout<<max(abs(a[N-1]-Y), abs(a[N-2]-a[N-1]))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int t;
            for (int k = 0; k < 30; k++) {
                if ((1 << k) & (i ^ j)) {
                    t = k + 1;
                    break;
                }
            }
            cout << t;
            if (j == n) {
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }
    cin.tie(0);
    ios::sync_with_stdio(false);
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int c[3][3];
  int i,k;
  bool x = true;
  for(i=0;i<=2;i++)
    for(k=0;k<=2;k++)
      cin >> c[i][k];
  for(i=0;i<=1;i++){
    if(c[i][0]-c[i][1] != c[i+1][0]-c[i+1][1]) x = false;
    if(c[i][1]-c[i][2] != c[i+1][1]-c[i+1][2]) x = false;
    }
  for(k=0;k<=1;k++){
    if(c[0][k]-c[1][k] != c[0][k+1]-c[1][k+1]) x = false;
    if(c[1][k]-c[2][k] != c[1][k+1]-c[2][k+1]) x = false;
    }
  if(x) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 384
read N
read W

sum=$(echo $W | tr ' ' '\n' | awk '{sum+=$1} END {print sum}')

acc=0
ans=''
for x in $W
do
    acc=$(($acc+$x))
    rest=$(($sum-$acc))
    if [ $acc -gt $rest ]; then
        V=$(($acc-$rest))
    else
        V=$(($rest-$acc))
    fi
    ans="$ans $V"
done

echo $ans | tr ' ' '\n' | sort -n | head -n1

Measured memory_bytes: 924
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int change = num%1000;
        if(change!=0){
            change = 1000 - change;
        }
        System.out.println(change);
        scan.close();
    }
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"

using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 10000000;
const ll inf = 1e9;

int main() {
	fastio;
	ll R, G, B, n;
	cin >> R >> G >> B >> n;
	ll r, g, b, cont = 0;
	f(i,0,n+1){
	r = i;
	f(j,0,n+1){
	g = j;
	b = (n - r*R - g*G)/B;
	if(b >= 0 && n - r*R - g*G == b*B) cont++;
 	}
	}
	cout <<cont<<endl;
 
	return 0;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[100010];
ll cnt[100010];

int main() {
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        cnt[a[i]]++;
    }
    int q;
    cin >> q;
    while (q--) {
        ll b,c;
        cin >> b >> c;
        sum -= b * cnt[b];
        sum += c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 5192
N=int(input())
S=input()
left=0
right=S[1:N].count('E')
ans=left+right
for i in range(1,N):
    if S[i-1]=='W':
        left+=1
    if S[i]=='E':
        right-=1
    ans=min(ans,left+right)
print(ans)

Measured memory_bytes: 9752
x,y = map(int, input().split())
ans = 0
if x*y<0:
    ans = abs(x+y) +1
else:
    ans = abs(x-y)
    if 0 < y and y < x:
        ans +=2
    elif x==0 and y < 0:
        ans +=1
    elif y < x and x < 0:
        ans +=2
    elif y==0 and x>0:
        ans +=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[2*100000+10];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        int tmp = max(a[i-1]-a[i],0);
        a[i] += tmp;
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4420
x1, y1, x2, y2 = map(int,input().split())

x3 = -y2+y1 + x2
y3 = x2-x1 + y2

x4 = -y3+y2 + x3
y4 = x3-x2 + y3

print('{} {} {} {}'.format(x3,y3,x4,y4))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll A, B;

bool is_prime(ll n) {
  if (n == 1) return true;
  for (ll i = 2; i*i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  cin >> A >> B;
  ll C = min(A, B);
  ll D = max(A, B);
  ll ans = 0;
  for (ll i = 1; i*i <= C; i++) {
    if (C % i == 0) {
      ll l = i;
      ll r = C/i;
      if (is_prime(l) && D % l == 0) {
        ans++;
      }
      if (is_prime(r) && D % r == 0 && l != r) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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


using namespace std;

int main(int argc, char *argv[])
{
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long ai = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    long long ci = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += ai*ci;
  }

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


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

using namespace std;

int main()
{

    string s;
    cin>>s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
    {
        cout<<3;
    }
    else if(s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R')
    {
        cout<<2;
    }
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
    {
        cout<<1;
    }
    else
    {
        cout<<0;
    }
    
    
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>

const int maxn=100;

int a[maxn+5],b[maxn+5];
int n,m,x,y;

inline bool check(int z)
{
	for(int i=1; i<=n; i++)
		if(!(a[i]<z))
			return 0;
	for(int i=1; i<=m; i++)
		if(!(b[i]>=z))
			return 0;
	return 1;
}

int main()
{
	scanf("%d %d %d %d", &n,&m,&x,&y);
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	for(int i=1; i<=m; i++)
		scanf("%d", &b[i]);
	for(int z=x+1; z<=y; z++)
		if(check(z))
		{
			puts("No War");
			return 0;
		}
	puts("War");
	
	return 0;
}

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

using namespace std;

using int64 = long long;

vector<int> ReadIntVector(int n) {
  vector<int> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  return xs;
}

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

  int n;
  cin >> n;
  vector<int> hs = ReadIntVector(n);
  vector<int> dp(n, INT32_MAX);
  dp[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(hs[i + 1] - hs[i]));
    if (i + 2 < n) {
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i + 2] - hs[i]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let W: usize = sc.cin();
    let mut values = vec![0u64; 200002];
    for _ in 0..n {
        let w: usize = sc.cin();
        let v: u64 = sc.cin();
        for k in (0..W).rev() {
            values[k + w] = max(values[k+w], values[k] + v);
        }
    }
    // trace!(&values);
    put!((0..W+1).map(|i| values[i]).max().unwrap());
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 6396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	s;
	ll		A=0;
	ll		B=0;
	cin >> n >> a >> b;
	cin >> s;

	n = s.size();
	for(i=0;i<n;i++) {
		if (s[i]=='c') {
			cout << "No" << endl;
		} else if (s[i]=='a') {
			if (a+b<=A+B) {
				cout << "No" << endl;
			} else {
				cout << "Yes" << endl;
				A++;
			}
		} else {
			if (a+b<=A+B) {
				cout << "No" << endl;
			} else {
				if (b>=B+1) {
					cout << "Yes" << endl;
					B++;
				} else {
					cout << "No" << endl;
				}
			}

		}
	}

	
	return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main()
{
    char s[4];
    int flag,count=0;
    scanf("%s", s);
    // for(int i=0; i<3; i++){
    //     if (s[i]=='R'){
    //         if (flag==1) count++;
    //         flag=1;
    //     }
    //     else
    //     {
    //         flag=0;
    //     }
    // }
    if (s[0]=='R'){
        if (s[1]=='R'){
            if (s[2]=='R') count=3;
            else count=2;
        }
        else count=1;
    }
    else {
        if (s[1]=='R'){
            if (s[2]=='R') count=2;
            else count=1;
        }
        else{
            if (s[2]=='R') count=1;
            else count=0;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 2100
using System;
class Program
{
	static void Main(string[] args)
	{
		//string[] input = Console.ReadLine().Split(' ');
		// 文字列の入力
		string s = Console.ReadLine();
        string t = Console.ReadLine();
        char[] sc = s.ToCharArray();
        char[] tc = t.ToCharArray();
        if(sc.Length != tc.Length - 1) Console.WriteLine("No");
        else
        {
          bool flg = true;
          for(int i=0; i<sc.Length; i++)
          {
            flg = flg && sc[i] == tc[i];
          }
          Console.WriteLine(flg ? "Yes" : "No");
        }
	}
}

Measured memory_bytes: 25792
/*ex7_3 hightierra*/
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int row,col,i,j;
    int *rowjudge;
    int *coljudge;
    char **matrix;
    scanf("%d %d",&row,&col);

    // 各行の配列へのメモリ領域の確保
    matrix = (char**)calloc(row, sizeof(char*));
    if(matrix == NULL){
        exit(1);
    }
    // 各行のメモリ領域の確保
    for(i = 0; i < row; i++){
        matrix[i] = (char*)calloc(col, sizeof(char));
        if(matrix[i] == NULL){
            exit(1);
        }
    }

    // 各メモリの確保
    rowjudge = (int*)calloc(row, sizeof(int));
    if(rowjudge == NULL){
        exit(1);
    }

    coljudge = (int*)calloc(col, sizeof(int));
    if(coljudge == NULL){
        exit(1);
    }

    // 入力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    // 各行、各列に黒が１つでもあるかを判別
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(matrix[i][j]=='#'){
                rowjudge[i]=1;
            }
        }
    }
    for(j=0; j<col; j++){
        for(i=0; i<row; i++){
            if(matrix[i][j]=='#'){
                coljudge[j]=1;
            }
        }
    }

    // 黒が１つでもある行と列の重なる要素のみを出力
    for(i=0; i<row; i++){
        for(j=0; j<col; j++){
            if(rowjudge[i]==1 && coljudge[j]==1){
                printf("%c",matrix[i][j]);
            }
        }
        if(rowjudge[i]==1){
            printf("\n");
        }
    }
 
    // 各メモリの開放
    for(i=0; i<row; i++){
        free(matrix[i]);
    }
    free(matrix);

    free(rowjudge);
    free(coljudge);

    return 0;
}

Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int gcm(int a, int b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
    }if (!(a % b))return b;
  return gcm(a % b, b);
}
long long gcm(long long a, long long b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
  }if (!(a % b))return b;
  return gcm(a % b, b);
}

int main()
{
  cin >> n >> m;
  VLL a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  VLL b(n);//2で割れる回数

  for (int i = 0; i < n; i++)
  {
    int cnt = 0;
    while ((a[i] / 2) * 2 == a[i])
    {
      cnt++;
      a[i] /= 2;
    }
    b[i] = cnt;
  }
  for (int i = 0; i < n-1; i++)
  {
    if(b[i+1]!=b[0]){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = a[0];
  for (int i = 0; i < n-1; i++)
  {
    ans = (ans / gcm(ans, a[i+1])) * a[i+1];
    if(ans>10000000000){
      cout << 0 << endl;
      return 0;
    }
  }
  ans *=pow(2, b[0]-1);
  cout << (m / ans + 1) / 2<<endl;
  return 0;
}


Measured memory_bytes: 1792
x = int(input())
for a in range(10**3):
    for b in range(10**3):
        if (a**5 - b**5 == x):
            print(a, b)
            exit()
        elif (-a**5 - b**5 == x):
            print(-a, b)
            exit()
        elif (a**5 + b**5 == x):
            print(a, -b)
            exit()
        elif -a**5 + b**5 == x:
            print(-a, -b)
            exit()


Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int N, K;
string S;
vector<int> C;

void input_init(void) {
	cin >> N >> K;
	cin >> S;
	S += (S[N - 1] == '0') ? '1' : '0';
	char c_top = S[0];
	int cnt = 1;
	C.push_back(0);
	for (int i = 1; i <= N; ++i) {
		char c_now = S[i];
		if (c_now == c_top)
			++cnt;
		else {
			C.push_back(cnt + C.back());
			c_top = c_now;
			cnt = 1;
		}
	}
}

int solve(void) {
	int sz = C.size() - 1;
	int k_cnt = sz / 2;
	if (S[0] == '0' && S[N - 1] == '0')
		++k_cnt;
	if (K >= k_cnt)
		return N;
	
	int max_val = -1;
	for (int i = 1; i <= sz; ++i) {
		int len = 2 * K;
		if ((S[0] == '1' && ((i - 1) % 2 == 0))
				|| (S[0] == '0' && ((i - 1) % 2 == 1)))
			++len;
		int r = i + len - 1;
		r = min(r, sz);
		int val = C[r] - C[i - 1];
		max_val = max(val, max_val);
		if (r > sz)
			break;
	}
	return max_val;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int V1, V2;
int size[1002];
int to[1002][1002];
int dist[1002];
int match[1002];
const int NIL = 1001;
bool BFS(){
  queue<int> que;
  REP(v, V1){
    if(match[v] == NIL){
      dist[v] = 0;
      que.push(v);
    }else{
      dist[v] = INF;
    }
  }
  dist[NIL] = INF;
  while(!que.empty()){
    int v = que.front(); que.pop();
    if(dist[v] < dist[NIL]){
      for(int i = 0; i < size[v]; i++){
        int u = to[v][i];
        if(dist[match[u]] == INF){
          dist[match[u]] = dist[v] + 1;
          que.push(match[u]);
        }
      }
    }
  }
  return dist[NIL] != INF;
}

bool DFS(int v){
  if(v != NIL){
    for(int i = 0; i < size[v]; i++){
      int u = to[v][i];
      if(dist[match[u]] == dist[v] + 1 && DFS(match[u])){
        match[u] = v;
        match[v] = u;
        return true;
      }
    }
    dist[v] = INF;
    return false;
  }
  return true;
}

int Hopcroft_Karp(){
  REP(v, V1 + V2) match[v] = NIL;
  int matching = 0;
  while(BFS()){
    REP(v, V1){
      if(match[v] == NIL && DFS(v)){
        matching ++;
      }
    }
  }
  return matching;
}
int memo[1000][1000];
int gcd(int x, int y){
  if(x < 1000){
    if(memo[x][y] != -1) return memo[x][y];
    int r = x % y;
    if(r == 0) return memo[x][y] = y;
    return memo[x][y] = gcd(y, r);
  }else{
    int r = x % y;
    if(r == 0) return y;
    return gcd(y, r);
  }
}
int main(){
  memset(memo, -1, sizeof(memo));
  while(scanf("%d %d", &V1, &V2) && (V1 != 0 || V2 != 0)){
    REP(i, V1) size[i] = 0;
    static int blue[500];
    static int red[500];
    REP(i, V1) scanf("%d", blue + i);
    REP(i, V2) scanf("%d", red + i);
    REP(u, V1) REP(v, V2){
      int x = max(blue[u], red[v]);
      int y = min(blue[u], red[v]);
      if(gcd(x, y) != 1) {
        to[u][size[u]++] = V1 + v;
        //G[u].push_back(V1 + v);
        //G[V1 + v].push_back(u);
      }
    }
    printf("%d\n", Hopcroft_Karp());
  }
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

vector<int> ball(200005,0);

void putball(int n){
  for(int i=1; i<=sqrt(n); i++){
    if(n%i==0){
      ball.at(i)++;
      if(i!=n/i)ball.at(n/i)++;
      //cout << "putball " << i << endl;
    }
  }
}

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  int ballcount = 0;
  vector<int> b;

  rep(i,n){
    int j = n-i;
    if((ball.at(j)%2)!=a.at(j-1)){
      putball(j);
      b.push_back(j);
      ballcount++;
      //cout << "putball " << j << endl;
    }
  }

  if((ball.at(1)%2)==a.at(0)){
    cout << ballcount << endl;
    rep(i,b.size()) cout << b.at(i) << " ";
  }else{
    cout << "-1";
  }
  
  //cout << "hoge";
  //rep(i,n) cout << ball.at(i+1) << " ";
}

Measured memory_bytes: 5360
#include<stdio.h>
int main(void){
	int num[10];
	int i,q,p;
	int tmp;
	for(i=0;i<3;i++){
		scanf("%d",&num[i]);
	}
	
	for(p=0;p<2;p++){
		for(q=p+1;q<3;q++){
			if(num[p]>num[q]){
				tmp=num[p];
				num[p]=num[q];
				num[q]=tmp;
			}
		}
	}
	for(i=0;i<3;i++){
		if(i != 2) printf("%d ",num[i]);
		else printf("%d\n", num[i]);
	}
	
	return 0;
	
}



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

// 1番短い串とペアを組むべきなのはその次に短い串。つまり貪欲法でOK
int main(){
  int N;
  cin >> N;
  int Nskew= 2*N;

  vector<int> data(Nskew);
  for(int i=0; i<Nskew; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());

  int ans= 0;
  for(int i=0; i<Nskew; i+=2){
    ans+= data.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
# F - LCS
s = input()
t = input()

m = len(s)
n = len(t)

# dp[i][j]: s の i 文字目、 t の j 文字目までを比較したときの LSC の長さ
dp = [[0]*(n+1) for _ in range(m+1)]

# 初期条件
# 0 文字目 (i=0 or j=0) のとき LSC は 0
for i in range(m+1):
    dp[i][0] = 0
for j in range(n+1):
    dp[0][j] = 0

# s の v 文字目について
for v in range(1,m+1):
    # t の w 文字目について
    for w in range(1,n+1):
        # s の v 文字目と t の w 文字目が同じとき
        if s[v-1] == t[w-1]:
            dp[v][w] = dp[v-1][w-1] + 1
        # s の v 文字目と t の w 文字目が異なるとき
        else:
            dp[v][w] = max(dp[v-1][w],dp[v][w-1])

# 文字列を 「復元」
# DP テーブルの値を見ながら、今いるノード (i,j) がどのノードから更新されて来たのかを特定する

# 遡った文字を保持する配列
res = []

# DP テーブルの末端の index
i = m
j = n
while (i>0 and j>0):
    # (i-1, j) -> (i, j) と遷移していた場合 (s[i-1] != t[j-1]) 
    if (dp[i][j] == dp[i-1][j]):
        # DP の遷移を i について 1 遡る
        i -= 1
    else:
        # (i, j-1) -> (i, j) と遷移していた場合 (s[i-1] != t[j-1]) 
        if (dp[i][j] == dp[i][j-1]):
            # DP の遷移を j について 1 遡る
            j -= 1
        # (i-1, j-1) -> (i, j) と遷移していた場合 (s[i-1] == t[j-1]) 
        else:
            # s[i-1] == t[j-1] なので、res.append(t[j-1]) でも良い
            res.append(s[i-1])
            # DP の遷移を遡る
            i -= 1
            j -= 1
            
# res は逆方向から取得したので reverse する
ans = list(reversed(res))
print(''.join(ans))

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

int digit_sum(int n) {
    int ans = 0;
    while (n > 0) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main(void) {
    int N;
    cin >> N;
    int ans = INT_MAX;
    for (int i = 1; i < N; i++) {
        ans = min(ans, digit_sum(N - i) + digit_sum(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){


    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];

    }

    sort(a,a+3,greater<int>());

    int res=(a[0]*10)+a[1]+a[2];
    cout<<res<<endl;

}


Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  int DIS[N];
  REP(i,N) DIS[i]=0;
  
  for(int i=1; i<N; ++i){
    for(int j=i+1; j<=N; ++j){
      int M=min(j-i,min(abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)));
      DIS[M]++;
    }
  }
  
  RREP(i,N-1) co(DIS[i]);
  return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll n,a,res;
set<pair<pair<ll,ll>,pair<ll,ll> > >used;
void rec(ll sum,ll cur,ll mul,ll cs){
	if(used.find(mp(mp(sum,cur),mp(mul,cs))) != used.end()) return;
	used.insert(mp(mp(sum,cur),mp(mul,cs)));
	if(sum >= n){
		res = min(res,cs);
		return;
	}
	if(res <= cs) return;
	rec(mul*cur,cur,mul*cur,cs+cur+a);
	if(cur > 1) rec(mul*(cur-1),cur-1,mul*(cur-1),cs+cur-1+a);
}
int main(){
	cin>>n>>a;
	res = n;
	for(int cut=2;cut<=15;cut++){
		//ub = pow(n,1/cut)+15 lb = pow(n,1/cut)-15
		double hoge = pow((double)(n),1.0/(double)(cut));
		int k = (int)(hoge);
	//	cout<<k<<endl;
		for(int beg=max(2,k-15);beg<=k+15;beg++){
			 for(int mask=0;mask<(1<<(cut-1));mask++){
			 	ll ret,cur = beg,mul = beg; int S = beg;
			 	bool ok = 0;
			 	for(int i=0;i<cut-1;i++){
			 		if(!((mask>>i)&1)){
			 			mul *= cur;
			 		}
			 		else{
			 			cur--;
			 			if(cur <= 0) goto bad;
			 			mul *= cur;
			 		}
			 		ret = mul;
			 		S += cur;
			 		if(mul > 1e13) ok = 1;
			 	}
			 	if(ok || ret >= n){
			 		res = min(res,1LL*S+1LL*(cut-1)*a);
			 	}
			 	bad:;
			 }
		}
	}
	for(int i=15;i>=2;i--) rec(i,i,i,i);
	cout<<res<<endl;
}

Measured memory_bytes: 18560
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Control.Monad.ST
import Data.Array.ST
import Data.Function

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    (x1:x2:x3:_) <- map (pred . length) . group . sort . ([1,2,3] ++) <$> getIntList
    print $ solve n x1 x2 x3

solve n x1 x2 x3 = runST $ do
    arr <- newArray ((-1,-1,-1),(n+1,n+1,n+1)) 0 :: ST s (STUArray s (Int,Int,Int) Double)
    forM_ [0..x3] $ \k -> do
        forM_ [0..x2+x3-k] $ \j -> do
            forM_ [0..x1+x2+x3-j-k] $ \i -> do
                unless (i+j+k == 0) $ do
                    a1 <- readArray arr (i-1,j,k)
                    a2 <- readArray arr (i+1,j-1,k)
                    a3 <- readArray arr (i,j+1,k-1)
                    let m = i + j + k
                    writeArray arr (i,j,k) $ ((fromIntegral n) + (fromIntegral i) * a1 + (fromIntegral j) * a2 + (fromIntegral k) * a3) / (fromIntegral m)
    ans <- readArray arr (x1,x2,x3)
    return ans

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

using namespace std;

constexpr int INF = (1 << 30) - 1;

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<int> ts;
    for(int i = 0 ; i < n - 1 ; ++i){
        int t;
        cin >> t;
        ts.emplace_back(t);
    }
    ts.emplace_back(0);

    vector< vector< vector<int> > > dp(2, vector< vector<int> >((n >> 1) + 1, vector<int>(2, INF)));
    dp[0][0][1] = ts[0];
    dp[0][1][0] = ts[0];

    for(int i = 1 ; i < n ; ++i){
        for(int j = 0 ; j <= (n >> 1) ; ++j){
            for(int k = 0 ; k < 2 ; ++k){
                dp[i & 1][j][k] = INF;
            }
        }

        for(int j = 0 ; j <= (n >> 1) ; ++j){
            for(int k = 0 ; k < 2 ; ++k){
                if(dp[1 ^ i & 1][j][k] == INF){
                    continue;
                }

                if(k == 0){
                    if(j + 1 <= (n  >> 1)){
                        chmin(dp[i & 1][j + 1][0], dp[1 ^ i & 1][j][0] - ts[i - 1] + ts[i]);
                    }
                    chmin(dp[i & 1][j][1], dp[1 ^ i & 1][j][0] + ts[i]);
                }else{
                    if(j + 1 <= (n >> 1)){
                        chmin(dp[i & 1][j + 1][0], dp[1 ^ i & 1][j][1] + ts[i]);
                    }
                    chmin(dp[i & 1][j][1], dp[1 ^ i & 1][j][1] - ts[i - 1] + ts[i]);
                }
            }
        }
    }

    int ans = min(dp[1 ^ n & 1][n >> 1][0], dp[1 ^ n & 1][n >> 1][1]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3692
f = true;
e = false;
while (s = gets) && !e do
  if f then
    f = false;
  else
    puts;
  end
  if s == "0 0" then
    e = true;
  else
    a = s.split(" ").map(&:to_i);
    a[0].times {
      puts "#" * a[1];
    }
  end
end

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

using namespace std;
struct CinInit
{
    CinInit()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} CinInit;

int main()
{
    int n, cnt = 0;
    cin >> n;
    vector<int> a(n);
    long long int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        ans += abs(a[i]);
        if (a[i] < 0)
            cnt++;
    }

    if (cnt % 2 == 1)
    {
        sort(a.begin(), a.end());
        for (int i = 0;; i++)
        {
            if (a[i] >= 0 || i == a.size() - 1)
            {
                ans -= 2 * min(abs(a[i]), abs(a[i - 1]));
                break;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    reverse_v = v[::-1]
    ans = 0

    # See:
    # https://www.youtube.com/watch?v=m-Nov1EvGoc
    for left in range(k + 1):
        for right in range(k - left + 1):
            if left + right > n:
                continue

            remain = k - (left + right)
            merged_v = sorted(v[:left] + reverse_v[:right])
            merged_v_len = len(merged_v)
            minus = 0

            for i in range(min(remain, merged_v_len)):
                if merged_v[i] < 0:
                    minus += merged_v[i]

            ans = max(ans, sum(merged_v) - minus)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[]= new int[n];
		int dp[]= new int[n+1];
		for(int i=0;i<n;i++)
		{
		a[i]= sc.nextInt();
		dp[i]=Integer.MAX_VALUE;
		}
		dp[0] = 0;
        dp[1] = dp[0] + Math.abs(a[0] - a[1]);
		for(int i=2;i<n;i++)
		{
		  dp[i]=Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));  
		}
		
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 60224
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

long long N, M,wa, K, W, ans[100],k[5];
string s[100],t[100];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		ans[i] = 0;
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> t[i];
	}
	
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			if (s[k] == s[i]) {
				ans[k]++;
				}
		}
		for (int j = 0; j < M; j++) {
			if (s[k] == t[j]) {
				ans[k]--;
			}
		}
	}
	wa = 0;
	for (int i = 0; i < N; i++) {
		wa = Lmax(ans[i], wa);
	}
	cout << wa << endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

vector<int> x(N);
rep(i,N) cin>>x[i];

int S=0;

rep(i,N) S+=2*min(x[i],K-x[i]);

cout<<S<<endl;

}

Measured memory_bytes: 256
package main

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

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

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

func main() {
	a := nextInt()
	p := nextInt()

	fmt.Println((a*3 + p) / 2)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,j, n,a,min = pow(10,9),k;
  cin>>n>>k;
  int h[n];
  for(i=0;i<n;i++)
    cin>>h[i];
  int cost[n];
  cost[0] = 0;
  for(i=0;i<k;i++)
  if(i<n)
  cost[i] = fabs(h[i] - h[0]);
  for(i=k;i<n;i++)
  {
  	for(j=0;j<k;j++)
  	{
     a = cost[i-j-1] + fabs(h[i]-h[i-j-1]);
     if(a<min) min = a;
	} 
	cost[i] = min;
	min = pow(10,9);
  }
  cout<<cost[n-1]<<"\n";
}

Measured memory_bytes: 1024
// E - League

// 有向グラフを用いる解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int MAX_N = 1000;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;

int players_to_game_idx[MAX_N][MAX_N];

struct Node {
	vector<int> next_nodes;
	bool visited = false;
	bool complete = false;
};

Node nodes[MAX_V];
int longest_path_length[MAX_V]; // nodes[i] からの最長パスの長さ
bool cycle = false;

int dfs(int idx) {
	if (nodes[idx].visited) {
		if (nodes[idx].complete) {
			return longest_path_length[idx];
		} else {
			cycle = true;
			return -1;
		}
	}

	nodes[idx].visited = true;

	for (int next_idx : nodes[idx].next_nodes) {
		longest_path_length[idx] = max(longest_path_length[idx], dfs(next_idx) + 1);
	}

	nodes[idx].complete = true;
	return longest_path_length[idx];
}



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

	int idx = 0;
	for (int i=0; i<N; i++) {
		for (int j=i+1; j<N; j++) {
			players_to_game_idx[i][j] = idx;
			players_to_game_idx[j][i] = idx;
			idx++;
		}
	}

	int V = idx;

	int A, player1, player2;
	for (int i=0; i<N; i++) {
		cin >> A;
		A--;
		player1 = i;
		player2 = A;
		int from_idx = players_to_game_idx[player1][player2];

		for (int j=1; j<N-1; j++) {
			cin >> A;
			A--;
			player2 = A;
			int to_idx = players_to_game_idx[player1][player2];
			nodes[from_idx].next_nodes.push_back(to_idx);
			from_idx = to_idx;
		}
	}

	/*
	// **** debug ****
	for (int i=0; i<N; i++) {
		for (int j=i+1; j<N; j++) {
			cout << i+1 << " " << j+1 << " -> " << players_to_game_idx[i][j] << endl;
		}
	}
	for (int i=0; i<V; i++) {
		for (int idx : nodes[i].next_nodes) {
			cout << i << "->" << idx << endl;
		}
	}
	*/


	for (int i=0; i<V; i++) {
		dfs(i);
	}

	if (cycle) {
		cout << -1 << endl;
		return 0;
	}

	int ans = 0;
	for (int i=0; i<V; i++) {
		ans = max(ans, longest_path_length[i] + 1) ;
		//cout << "idx=" << i << " longest path=" << longest_path_length[i] + 1 << endl; // **** debug ****
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 37376
#include <algorithm>
#include <cstdio>
#include <tuple>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

vector<bool> sieve_of_eratosthenes(int n) { // enumerate primes in [2,n] with O(n log log n)
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= n; ++i)
        if (is_prime[i])
            for (int k = 2 * i; k <= n; k += i)
                is_prime[k] = false;
    return is_prime;
}

constexpr int max_n = 1000000;
constexpr int sqrt_max_n = 1000;
constexpr int height = sqrt_max_n + 100;
constexpr int width = sqrt_max_n + 100;
constexpr int center_y = height / 2;
constexpr int center_x = width / 2;
const int dy[] = { 0, -1, 0, 1 };  // RULD
const int dx[] = { 1, 0, -1, 0 };

int main() {
    // fill the caves
    auto cave = vectors(height, width, int());
    vector<pair<int16_t, int16_t> > rev_cave(max_n + 1);
    {
        int y = center_y;
        int x = center_x;
        int dir = 3;  // D
        repeat (i, max_n) {
            cave[y][x] = i + 1;
            rev_cave[i + 1] = { y, x };
            int ly = y + dy[(dir + 1) % 4];
            int lx = x + dx[(dir + 1) % 4];
            if (not cave[ly][lx]) {
                dir = (dir + 1) % 4;
            }
            y += dy[dir];
            x += dx[dir];
        }
    }
    auto is_prime = sieve_of_eratosthenes(max_n);
    // solve
    while (true) {
        // input
        int m, n; scanf("%d%d", &m, &n);
        if (m == 0 and n == 0) break;
        // dp
        auto dp = vectors(height, width, int());
        int y, lx; tie(y, lx) = rev_cave[n];
        int rx = lx + 1;
        pair<int, int> result = {};
        while (y < height) {
            repeat_from (x, lx, rx) {
                int k = cave[y][x];
                if (k and k <= m) {
                    dp[y][x] = max({ dp[y - 1][x - 1], dp[y - 1][x], dp[y - 1][x + 1] });
                    if (is_prime[k]) {
                        dp[y][x] += 1;
                        setmax(result, make_pair(dp[y][x], k));
                    }
                }
            }
            // incr
            ++ y;
            lx = max(1, lx - 1);
            rx = min(width - 1, rx + 1);
        }
        // output
        if (result.first == 0) result.second = 0;
        printf("%d %d\n", result.first, result.second);
    }
    return 0;
}

Measured memory_bytes: 15964
use std::io;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::new();
    let a: usize = input.next();
    let b: usize = input.next();
    if a%3 == 0 || b%3 == 0 || (a+b)%3 ==0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}

struct Input {
    queue: VecDeque<String>,
}

impl Input {
    fn new() -> Input {
        Input { queue: VecDeque::new() }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        if self.queue.is_empty() {
            let mut line = String::new();
            let _ = io::stdin().read_line(&mut line);
            for x in line.split_whitespace() {
                self.queue.push_back(String::from(x));
            }
        }
        return self.queue.pop_front().unwrap().parse::<T>().unwrap();
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<P> to[100005];
int edge[100005];
bool used[100005];

void bfs(int a) {
    queue<P> q;
    q.push(P(a, -1));
    used[a] = true;
    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        int num = 0;
        for (auto p: to[v.first]) {
            if (used[p.first]) continue;
            //if (edge[z]>0) continue;
            num++;
            if (num==v.second) num++;
            int id = p.second;
            edge[id] = num;
            q.push(P(p.first, num));
            used[p.first] = true;
        }
    }
    
}

int main(){
    int n;
    cin >> n;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b, i);
        to[b].emplace_back(a, i);
    }
    bfs(0);
    int ans = 0;
    rep(i, n-1) {
        ans = max(ans, edge[i]);
    }
    cout << ans << endl;
    rep(i, n-1) {
        cout << edge[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <string>
//#include <iterator>
#include <algorithm>

using namespace std;

char change(char c)
{
	if ( isupper(c) ) {
		return tolower(c);
	} else if ( islower(c) ) {
		return toupper(c);
	} else {
		return c;
	}
}


int main() {

	string s;

	getline(cin, s);
	transform(s.begin(), s.end(), s.begin(), change);
	cout << s << endl;

	return 0;
}



Measured memory_bytes: 3112
#define _CRT_SECURE_NO_WARNINGS
#define TASK "complex"
#pragma comment(linker, "/STACK:2010886400")
#include <cstdio>
#include <iostream>
#include <iomanip> 
#include <cmath>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000001;
const long double EPS = 1e-9;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

long long nextLong(long long l, long long r) {
	uniform_int_distribution <long long> foo(l, r);
	return foo(rnd);
}

double nextDouble(double l, double r) {
	uniform_real_distribution <double> foo(l, r);
	return foo(rnd);
}

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void myReturn(int code = 0) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

bool dp[4010][32010];

bool canReach(int x, vector <int> &dx) {
	memset(dp, 0, sizeof dp);
	dp[0][16000] = true;
	for (int i = 0; i < dx.size(); ++i) {
		for (int j = 0; j <= 32000; ++j) {
			if (dp[i][j]) {
				if (j - dx[i] >= 0) {
					dp[i + 1][j - dx[i]] = true;
				}
				if (j + dx[i] <= 32000) {
					dp[i + 1][j + dx[i]] = true;
				}
			}
		}
	}
	return dp[dx.size()][16000 + x];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
#endif

	string s;
	int x, y;
	cin >> s >> x >> y;

	int curSize = 0, cntGroups = 0;
	vector <int> dx, dy;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'F') {
			++curSize;
		}
		else {
			if (curSize > 0) {
				if (cntGroups == 0) {
					x -= curSize;
				}
				else if (cntGroups % 2 == 0) {
					dx.push_back(curSize);
				}
				else {
					dy.push_back(curSize);
				}
			}
			curSize = 0;
			++cntGroups;
		}
	}
	if (curSize > 0) {
		if (cntGroups == 0) {
			x -= curSize;
		}
		else if (cntGroups % 2 == 0) {
			dx.push_back(curSize);
		}
		else {
			dy.push_back(curSize);
		}
	}

	if (canReach(x, dx) && canReach(y, dy)) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	myReturn();
}

Measured memory_bytes: 125696
#include <iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include<queue>
#include<unordered_map>
#include<cmath>
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define ll long long int
#define pi (double)3.14159265359
#define vect vector <int>
#define pb push_back
using namespace std;

void solve() {
	int temp;
	int x = 5,z=1;
	while (x--) {
		cin >> temp;
		if (temp == 0) {
			cout << z << endl;
			break;
		}
		z++;
	}
}
int main(){
	solve();
	return 0;
}


Measured memory_bytes: 3608
A, B, C = map(int, input().split())
M = max(A, B, C)
cnt = 0
dev_result = 0
for i in [A, B, C]:
    cnt += (M - i) // 2
    if (M - i) % 2 == 1:
        dev_result += 1
if dev_result == 1:
    print(cnt + 2)
elif dev_result == 2:
    print(cnt + 1)
else:
    print(cnt)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

q = int(input())

def eratosthenes2(limit):
    is_prime = [1] * (limit + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(limit**0.5) + 1):
        if is_prime[i]==0:
            continue
        for j in range(i * 2, limit + 1, i):
            is_prime[j] = 0
    return is_prime

limit = 10**5

is_prime = eratosthenes2(limit)
prime_list = [i for i in range(limit + 1) if is_prime[i]]

like_2017=[0]*limit

for p in prime_list:
    if is_prime[(p+1)//2]==1:
        like_2017[p] = 1

from itertools import accumulate
B = [0] + like_2017
B = list(accumulate(B))

ans=[0]*q
for i in range(q):
    l, r = map(int, input().split())
    ans[i]=B[r+1]-B[l]

print(*ans,sep='\n')


Measured memory_bytes: 14288