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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v) {
  os << "[";
  for(int i = 0; i < v.size(); i++) {
    if(i) os << ", ";
    os << v[i];
  }
  os << "]";
  return os;
}

LL Brute(const vector<LL> &v) {
  int n = v.size();
  vector<LL> sums;
  for(int mask = 1; mask < (1 << n); mask++) {
    LL temp = 0;
    for(int b = 0; b < n; b++) {
      if((1 << b) & mask) temp += v[b];
    }
    sums.push_back(temp);
  }
  sort(sums.begin(), sums.end());
  assert(sums.size() == (1 << n) - 1);
  int size = sums.size();
  return sums[size / 2];
}

bitset<int(2000 * 2000 + 100)> bs;

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<LL> A(n);
  bs.set(0);
  LL sum = 0;
  for(LL &x: A) cin >> x, bs |= bs << x, sum += x;
  sum = (sum + 1) / 2;
  LL ans;
  for(ans = sum; ; ans++) {
    assert(ans < bs.size());
    if(bs.test(ans)) {
      break;
    }
  }
#ifdef LOCAL
  cerr << ans << " " << Brute(A) << endl;
  assert(ans == Brute(A));
#endif
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];

	int max = *max_element(all(a));

	int mid = (max + 1) / 2;
	int midi, midmin = INT_MAX;
	rep(i, n) {
		if (midmin > abs(mid - a[i]) && a[i] != max) { midi = i; midmin = abs(mid - a[i]); }
	}
	cout << max << " " << a[midi] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>

using namespace std;

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

	if (abs(c - a) <= d) {
		cout << "Yes" << endl;
	}
	else if (abs(b - a) <= d && abs(c - b) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
	int a;
	int b;
	int n;
	int c;

	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);
		a = a*a;
		b = b*b;
		c = c*c;
		if (a + b == c || b + c == a || c + a == b){
			printf("YES\n");
		}
		else printf("NO\n");
	}

		return 0;
	}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define itn int
typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int N;
  cin >> N;
  vector<int> c(N, 0);
  vector<int> s(N, 0);
  vector<int> f(N, 0);

  for (int i = 0; i < N - 1; i++){
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int i = 0; i < N - 1; i++)
  {
    int now = s[i] + c[i];
    for (int j = i + 1; j < N - 1; j++){
      if (now <= s[j]) {
        now = s[j];
      }else{
        now = ceil((now - s[j]) / double(f[j])) * f[j] + s[j];
      }
      now += c[j];
    }
    cout << now << endl;
  }


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

Measured memory_bytes: 256
g = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
x, y = gets.split.map(&:to_i)
ans = false
3.times { |i|
  if g[i].index(x) && g[i].index(y)
    ans = ans || true
  end
}
puts (ans ? "Yes" : "No")

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#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 eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll linf=1e18;
const int inf=1001001001;
const ll mod=1e9+7; // 998244353 = (119<<23)+1
// head
const int nax=1e5+7;
int n,k,r,sc,p;
string s;
pair<char,int> g[nax];
int main() {
	  ios::sync_with_stdio(false);
  	cin.tie(0);
		cin>>n>>k>>r>>sc>>p>>s;
		int ans=0;
		rep(i,0,k) {
			if(s[i]=='r') {
				ans+=p;
				g[i]=mp('p',1);
			} else if(s[i]=='s') {
				ans+=r;
				g[i]=mp('r',1);
			} else {
				ans+=sc;
				g[i]=mp('s',1);
			}
		}
		rep(i,k,n) {
			if(s[i]=='r') {
				g[i].fi='p';
			} else if(s[i]=='p') {
				g[i].fi='s';
			} else {
				g[i].fi='r';
			}
			if(g[i-k].se==0||g[i-k].fi!=g[i].fi) {
				if(s[i]=='r') {
					ans+=p;
				} else if(s[i]=='p') {
					ans+=sc;
				} else {
					ans+=r;
				}	
				g[i].se=1;
				continue;
			}
		}
		cout<<ans;
		return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>

int main( void ) {
	char tStr[ 3 ];
	int i, sum[ 4 ] = {};

	while ( scanf( "%*d,%s", tStr ) == 1 )
		switch ( tStr[ 0 ] ) {
			case 'A': sum[ tStr[ 1 ] == 'B' ? 1 : 3 ]++; break;
			case 'B': sum[ 2 ]++; break;
			case 'O': sum[ 0 ]++; break;
		}

	for ( i = 4; i--; printf( "%d\n", sum[ i ] ) ) ;

	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      
     Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] number = new int[N];

		int count = 0;

		//偶数判定（2で割り切れなくなるまで）
		for (int i = 0; i < N; i++) {
			number[i] = sc.nextInt();
			while (number[i] % 2 == 0) {
				number[i] /= 2;
				count++;
			}
		}
		System.out.println(count);
    }
}


Measured memory_bytes: 34252
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

int n,K;

int main(){
	read(K);
	if(K==1)return puts("1\n1"),0;
	if((K+1)/2%2==0){
		n=(K+1)/2,printf("%d\n",n);
		rep(i,1,n){
			rep(j,1,n){
				int t=i+j-1;
				if(t>n)t-=n;
				printf("%d ",min(K,t*2-1+(j&1)));
			}
			puts("");
		}
	}
	else{
		n=(K+1)/2+1,printf("%d\n",n);
		rep(i,1,n){
			rep(j,1,n){
				int t=i+j-1;
				if(t>n)t-=n;
				int x=t*2-1+(j&1);
				if(K==2*n-2&&t>=n-1)x=K-(n-t);
				else if(K==2*n-3&&t>=n-2)x=K-(n-t);
				printf("%d ",x);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n>>k;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(rall(v));
    for(ll i=k;i<n;i++) sum+=v[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4756
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[5];
        var b = new int[5];
        for (int i = 0; i < 5; i++)
        {
            a[i] =  int.Parse(Console.ReadLine().Trim());
            b[i] = a[i] % 10;
        }
        var t = 100; var ti = 0;
        for (int i = 0; i < 5; i++)
        {
            if (b[i] != 0)
                if (b[i] < t) { ti = i;  t = b[i]; }
        }
        if (t == 100) { Console.WriteLine(a.Sum()); goto exit; }
        var ans = 0;
        for (int i = 0; i < 5; i++)
        {
            if (i != ti) ans += ((a[i] + 9) / 10) * 10;
            else ans += a[i];
        }
        Console.WriteLine(ans);
        exit:;
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  
int a,b,i;  
cin >>a>>b;
  
  if(a<b){
  for(i=0;i<b;i++){
  cout<<a;
  }
  }else{
  for(i=0;i<a;i++){
  cout<<b;
  }
  }
  
return 0;
 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M, X = map(int, input().split())
C = []
A = []
for _ in [0]*N:
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)

INF = 10**10
ans = INF 
for bit in range(1 << N):
    S = [0]*M
    cost = 0
    for i in range(N):
        if bit >> i & 1:
            cost += C[i]
            for j in range(M):
                S[j] += A[i][j]

    if min(S) >= X and cost < ans:
        ans = cost

print(ans if ans < INF else -1)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } 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; }

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, s.size()) {
    cout << char((((s[i] + n) - 'A') % 26) + 'A');
  }
  cout << endl;
}


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

public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
}

Measured memory_bytes: 71948
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
LL a[404];
LL dp[404][404];
LL rui[404];

int main(){
    cin >> n;
    REP(i, n)cin >> a[i];
    REP(i, n)rui[i + 1] = rui[i] + a[i];
    REP(i, 404)REP(j, 404)dp[i][j] = HINF<LL>();
    REP(i, n)dp[i][i] = 0;
    for(int len = 2;len <= n;len++){
        for(int l = 0;l + len - 1 < n;l++){
            for(int r = l + 1;r <= l + len - 1;r++){
                dp[l][l + len - 1] = min(dp[l][l + len - 1], dp[l][r - 1] + dp[r][l + len - 1] + (rui[l + len] - rui[l]));
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=4e5+100;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int head[N],nxt[N],to[N],fa[N];
int sum[N],all;bool is[N];
LL ans;
int one[N],two[N];
inline void dfs1(int k) {
	sum[k]=is[k];
	for (int i=head[k];i;i=nxt[i])
		if (to[i]!=fa[k]) {
			fa[to[i]]=k;
			dfs1(to[i]);
			if (one[to[i]]+1>one[k])
				two[k]=one[k],one[k]=one[to[i]]+1;
			else two[k]=max(two[k],one[to[i]]+1);
			sum[k]+=sum[to[i]];
		}
}
inline void dfs2(int k,int mx) {
	int l=all-sum[k]?mx:1<<30,r,i,One=mx,Two=0;
	for (i=head[k];i;i=nxt[i])
		if (to[i]!=fa[k]) {
			if (one[to[i]]+1>One)
				Two=One,One=one[to[i]]+1;
			else Two=max(Two,one[to[i]]+1);
			if (sum[to[i]]) l=min(l,one[to[i]]+1);
		}
	r=One==Two?One-1:(One==Two+1?Two:Two+1);
	if (is[k]) ans+=r+1;
	else if (l<=r) ans+=r-l+1;
	for (i=head[k];i;i=nxt[i])
		if (to[i]!=fa[k])
			dfs2(to[i],(one[to[i]]+1==One?Two:One)+1);
}
int main()
{
	int n=gi(),i,a,b,tot=0;char c;
	for (i=1;i<n;i++) {
		a=gi(),b=gi();
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot;
	}
	for (i=1;i<=n;all+=is[i++]=c-'0') while ((c=getchar())<'0'||'9'<c);
	dfs1(1);
	dfs2(1,0);
	cout<<ans+1<<endl;
	return 0;
}


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

A = [[0]*W for i in range(H)]
data = [0]*(H*W+1)

for i in range(H):
    A[i] = list(map(int,input().split()))

for i in range(H):
    for j in range(W):
        data[A[i][j]] = [i,j]

Q = int(input())

L = [0] * Q
R = [0] * Q

for i in range(Q):
    L[i],R[i] = map(int,input().split())

X = [0]*(H*W+1)

for i in range(D):
    x = H*W-D-i
    count = 0
    while x > 0:
        count += abs(data[x][0]-data[x+D][0])+abs(data[x][1]-data[x+D][1])
        X[x] += count
        x -= D

for i in range(Q):
    print(X[L[i]]-X[R[i]])

Measured memory_bytes: 28588
#include<stdio.h>

int main(void){
int H,W,i,I,j;
for(j=0;j<10000;j++){
	scanf("%d %d",&H,&W);
	if(H!=0){
	for(i=0;i<H;i++){
		if(i==0||i==H-1){
		
			for(I=0;I<W;I++){
			printf("#");
		}
				printf("\n");
	}else{
		for(I=0;I<W;I++){
			if(I==0||I==W-1){
			printf("#");	
			}else{
					printf(".");
			}
			
	}
	printf("\n");
	}
	}
	}else{
	break;
		}

	printf("\n");


			
		}
	
	return 0;
}


Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll findlcm(ll arr[], ll n)
{
    // Initialize result
    ll ans = arr[0];

    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
bool mycompare(const tuple< double, int,int>  &lhs, const tuple< double, int,int>  &rhs){
    if(get<0>(lhs) == get<0>(rhs))
    return get<2>(lhs) < get<2>(rhs);
    else  return get<0>(lhs) > get<0>(rhs);
}
ll solve(ll n,ll a[],ll b[],ll dp[],int m)
{
    if(n<=0)
    {
        return 0;
    }
    if(dp[n]!=1000000007)
    {
        return dp[n];
    }
    for(ll i=0;i<m;i++)
    {
       dp[n]= min(dp[n],b[i]+solve(n-a[i],a,b,dp,m));
    }
    return dp[n];
}
int main()
{
     ll n,i,j,cnt=0,k,w=-100,h,m,hcf,prod,t;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
    cin>>n>>m;
    ll a[m],b[m];
    for(i=0;i<m;i++)
    {
        cin>>a[i]>>b[i];
    }
    ll dp[10001];
    for(i=0;i<=10000;i++)
    {
        dp[i]=1000000007;
    }

    cout<<solve(n,a,b,dp,m);




	    return 0;
}


Measured memory_bytes: 1280
#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; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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; }

//

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
const ll INF = 1e18;

struct Edge {
    int to, a, b;
    Edge(int to, int a, int b):to(to), a(a), b(b) {}
};

struct Data {
    int v, s; ll x;
    Data(int v, int s, ll x):v(v), s(s), x(x) {}
    bool operator<(const Data &r) const {return r.x < x; };
};

vector<Edge> g[MAX_V];
// dp[今いる頂点][j円で来るとき] = 最短時間
ll dp[MAX_V][MAX_S+5];

int main() {
    int n, m, s;
    cin >> n >> m >> s;
    for(int i = 0; i < m; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u; --v;
        g[u].emplace_back(v, a, b);
        g[v].emplace_back(u, a, b);
    }
    vector<int> cvec(n);
    vector<int> dvec(n);
    for(int i = 0; i < n; ++i) cin >> cvec[i] >> dvec[i];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < MAX_S+5; ++j) {
            dp[i][j] = INF;
        }
    }
    s = min(s, MAX_S);  // 所持金がMAX_Sより大きかったら十分にお金を持っている

    priority_queue<Data> pque;
    auto push = [&](int v, int s, ll x) {
        if(s < 0) return;
        if(dp[v][s] <= x) return;   // ダイクストラの行き先がすでに小さかったらの処理
        dp[v][s] = x;
        pque.emplace(v, s, x);
    };

    push(0, s, 0);      // 始点の金額を入れる
    while(!pque.empty()) {
        Data now = pque.top(); pque.pop();
        int v = now.v, s = now.s;
        ll x = now.x;
        if(dp[v][s] != x) continue;     // 最短時間が上書きされていることがあるので☑
        int ns = min(s+cvec[v], MAX_S);     // 所持金がMAX_Sより多いか
        push(v, ns, x+dvec[v]);     // 両替はその頂点に来た時にO(1)で行われる
        for(auto e : g[v]) {
            // 移動に関しては頂点の辺の数だけ操作がある
            push(e.to, s-e.a, x+e.b);   
        }
    }
    for(int i = 1; i < n; ++i) {
        ll ans = INF;
        for(int j = 0; j < MAX_S+5; ++j) chmin(ans, dp[i][j]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 6372
k = int(input())

ans = 1
used = [False]*k
now = 7%k
pow7 = 7
while not used[now]:
    if now == 0:
        print(ans)
        exit()
    used[now]=True
    pow7 = (pow7*10)%k
    now = (now+pow7)%k
    ans+=1
print(-1)



Measured memory_bytes: 16588
#include <iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
 
  long long ans = 0;
  for (int i = 0; i <= N; i++)
  {
    if(i % 3 != 0 && i % 5 != 0){
      ans += i;
    }
  }
  cout << ans;
}
 

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

int main() {
  float a,b,c,d,e,f;
  float det;

  while( cin >> a >> b >> c >> d >> e >> f ) {
    det = a*e-b*d;
    float x = (c*e-f*b)/det;
    float y = (-c*d+f*a)/det;
    x = (x==-0.0)?0.0:x;  // Convert -0.0 to 0.0
    y = (y==-0.0)?0.0:y;
    cout << setiosflags(ios::fixed) << setprecision(3);
    cout << x << " " << y << endl;
  }

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define pb push_back
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vstr = vector<string>;
static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

void solve(ll N) {
  int cnt = 0;
  for (auto x: to_string(N)) cnt += (x == '2');
  cout << cnt << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
 
/*sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);*/
 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
 
struct debug {
	~debug() { cerr << endl; }
	
	//eni(!=) cerr << boolalpha << i; ris; }        Part 1
	
	template < class c > typename \
	enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i;
		return * this;
	}
	
	//eni(==) ris << range(begin(i), end(i)); }     Part 2
	
	template < class c > typename \
	enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return * this << range(begin(i), end(i)); 
	}
	
	/*sim, class b dor(pair < b, c > d) {           Part 3
		ris << "(" << d.first << ", " << d.second << ")";
	}*/
	
	template < class c, class b > debug & operator << (pair < b, c > d) {
		return * this << "(" << d.first << ", " << d.second << ")";
	}
	
	/*sim dor(rge<c> d) {                           Part 4
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		ris << "]";
	}*/
	
	template < class c > debug & operator <<(rge<c> d) {
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
			*this << ", " + 2 * (it == d.b) << *it;
		return * this << "]";
	}
	
};

 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back
int INF = 1e9;
int arr[7] = {0, 1, 3, 2, 4, 6, 5};

int gcd(int a, int b){
	return __gcd(a, b);
}
void read(vector<ll> &a){
	for(ll &i : a) cin >> i;
}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}

void test_case(int tnum){
	int n;
	cin >> n;
	int d = 0;
	bool ok = 0;
	for(int i = 0; i < n; i++){
		int u, v;
		cin >> u >> v;
		if(u == v){
			d++;
		} else {
			d = 0;
		}
		if(d >= 3){
			ok = 1;
		}
	}
	string ans = ok ? "Yes" : "No";
	cout << ans;
}

 
//Can the answaer be binary searched?
//Any special cases? n=1/0;
//n^2 does it?
//Dp state?
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	t = 1;
	// cin >> t;

	
	for(int i =1; i<=t;i++){
		test_case(i);
	}
}

Measured memory_bytes: 3636
/*1.4*/
#include "bits/stdc++.h"
using namespace std;


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

    int h[n];
    for(int i = 0; i < n; ++i) cin >> h[i];

    int dp[n];
    for(int i = 0; i < n; ++i) dp[i] = 1e9;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for(int i = 2; i < n; ++i) {
        for(int j = max(0, i-k); j < i; ++j) {
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
        // cout << i << " " << dp[i] << endl;
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
from math import ceil
N, H = map(int, input().split())
a = [list(map(int, input().split()))for _ in range(N)]
a.sort(key=lambda x: x[1], reverse=True)
s = 0
ans = 0
m = max(a, key=lambda x: x[0])[0]
for n in a:
    if m < n[1]:
        s += n[1]
        ans += 1
        if s >= H:
            break
else:
    ans += ceil((H - s) / max(a, key=lambda x: x[0])[0])
print(ans)


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

int main(){
  ll n,a,b,ans;cin>>n>>a>>b;
  ans=(n/(a+b))*a;
  n-=(n/(a+b))*(a+b);
  ans+=min(n,a);
  cout<<ans;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

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

const ll MOD = (ll)1e9 + 7;

ll fact[1000005], invfact[1000005];

ll fastExp(ll base, ll p) {
	ll ret = 1;
	while (p) {
		if (p & 1ll) {
			ret *= base;
			ret %= MOD;
		}
		base *= base;
		base %= MOD;
		p >>= 1ll;
	}
	return ret;
}

ll comb(ll a, ll b) {
	ll ret = fact[a] * invfact[b];
	ret %= MOD;
	ret *= invfact[a-b];
	ret %= MOD;
	return ret;
}

int main() {
	fact[0] = 1;
	invfact[0] = 1;
	for (ll i = 1; i <= 1000000; i++) {
		fact[i] = i * fact[i-1];
		fact[i] %= MOD;
		invfact[i] = fastExp(fact[i], MOD-2);
	}
	int x,y;
	scanf("%d %d", &x, &y);
	ll ans = 0;
	for (int a = x%2; a <= x; a += 2) {
		int b = (x-a)/2;
		if (2*a + b != y) continue;
		ans += comb(a+b, b);
		ans %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b; cin >> a >> b;

  if (a <= 8 && b <= 8) cout << "Yay!" << "\n";
  else cout << ":(" << "\n";
}


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

int main() {
    std::string S, T, U;
    int A, B;
    std::cin >> S >> T >> A >> B >> U;

    if (S == U) {
        std::printf("%d %d\n", A - 1,  B);
    } else {
        std::printf("%d %d\n", A,  B - 1);
    }

    return 0;
}


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

using namespace std;


const int N = 1e5 + 5 , M = 5;

int happiness[N][M];
int maxHappiness[N][M]; // definition: maximum happiness on day N by doing activity M on that day

int n;

main(){

    scanf("%d" , &n);

    for(int day = 0 ; day < n ; day ++){

            for(int activity = 0 ; activity < 3 ; activity ++){

                    scanf("%d" , &happiness[day][activity]);

            }
    }

    // initialize dp table with base values
    maxHappiness[0][0] = happiness[0][0];
    maxHappiness[0][1] = happiness[0][1];
    maxHappiness[0][2] = happiness[0][2];

    for(int currentDay = 1 ; currentDay < n ; currentDay ++){

            for(int newActivity = 0 ; newActivity < 3 ; newActivity ++){

                    for(int lastActivity = 0 ; lastActivity < 3 ; lastActivity ++){


                            if(newActivity == lastActivity) continue; // same activity

                            maxHappiness[currentDay][newActivity] =

                            max(maxHappiness[currentDay  ][newActivity ] ,
                                maxHappiness[currentDay-1][lastActivity] + happiness[currentDay][newActivity]);

                    }

            }
    }

    int ans = max({maxHappiness[n-1][0] , maxHappiness[n-1][1] , maxHappiness[n-1][2]});
    printf("%d\n" , ans);

    return 0;
}


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

vector<vector<int>> rev;

int dfs(int v){
    if(rev[v].size() == 0) return 0;
    vector<int> children;
    for(int to: rev[v]){
        children.push_back(dfs(to));
    }
    sort(children.begin(), children.end());
    int ret = 0;
    for(int res: children){
        ret = max(ret + 1, res + 1);
    }
    // cout << v << " " << ret << " " << children.size() << endl;
    return ret;
}

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

    rev.assign(N, vector<int>());
    vector<int> a(N, 0);
    for(int i=1;i<N;i++){
        cin >> a[i];
        a[i]--;
        rev[a[i]].push_back(i);
    }

    cout << dfs(0) << endl;

    return 0;
}

Measured memory_bytes: 13952
n=int(input())
a=list(map(int,input().split()))
s=sum(a)/n
ans=0
if s==int(s):
    for i in range(n):
        ans+=(a[i]-int(s))**2
    #print(ans)
elif s+0.5>=sum(a)//n+1:
    for i in range(n):
        ans+=(a[i]-(sum(a)//n+1))**2
else:
    for i in range(n):
        ans+=(a[i]-sum(a)//n)**2
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;
  
int main()
{
	int n, a, b;
	string str, strl, strr, cmd, p;
	
	cin >> str;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> cmd >> a >> b;
		if (cmd == "replace") {
			strl.clear();
			strr.clear();
			cin >> p;
			for(int j = 0; j < a; j++)
				strl += str[j];
			strr = str.substr(b+1);
			str = strl + p + strr;
		}
		else if (cmd == "reverse") {
			strl.clear();
			p.clear();
			strr.clear();
			for(int j = 0; j < a; j++)
				strl += str[j];
			for(int j = b; j >= a; j--)
				p = p + str[j];
			strr = str.substr(b+1);			
			str = strl + p + strr;
		}
		else if (cmd == "print") {
			for(int j = a; j <= b; j++)
				cout << str[j];
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3180
import java.util.Scanner;

public class Main {
	static int p[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
//		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();

		int h = (int) Math.ceil((double)s.length/2);

		int c = 0;
		for(int i = 0; i+h < s.length; i++) {
			if(s[i] != s[s.length - i-1])
				c++;
		}

		System.out.println(c);

        return;
    }
}



Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    long    long    int min=10000000;
    long    long    int max=-100000000;
    long    long    int x,sum=0;
    for(int i=0;i<n;i++){
        cin>>x;
        if(min>x){
            min=x;
        }
        if(max<x){
            max=x;
        }
        sum=sum+x;
    }
    cout<<min<<" ";
    cout<<max<<" ";
    cout<<sum<<endl;
}



Measured memory_bytes: 3088
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


l, r = li()
MOD = 2019

ans = float("inf")
if r-l >= 2018:
    ans = 0
else:
    for i in range(l, min(r+1, l+2*MOD)):
        for j in range(i+1, min(r+1, l+2*MOD)):
            ans = min(ans, i*j % MOD)

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int direction = 1, top=500000, length=0;
		String s = sc.next();
		char[] string = new char[1000000];
		length = s.length();
		char[] temp = s.toCharArray();
		for(int i=0;i<length;i++) string[top+i] = temp[i];
		int q=sc.nextInt();
		for(int i=0;i<q;i++) {
			int t = sc.nextInt();
			if(t==1) {
				if(direction==1) direction=2;
				else direction=1;
			}else {
				int f = sc.nextInt();
				char c = sc.next().toCharArray()[0];
				length++;
				if((f==1 && direction==1) || (f==2 && direction==2)) {
						top--;
						string[top]=c;
				}else{
					string[top+length-1]=c;
				}
 			}
		}
		if(direction==1) {
			for(int j=top;j<top+length;j++) System.out.print(string[j]);
		}else {
			for(int j=top+length-1;j>=top;j--) System.out.print(string[j]);
		}
		System.out.println();
	}
}

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

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

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

  vector<int64_t> A(N);
  rep(i,N) cin >> A.at(i);

  sort(A.begin(), A.end());
  int64_t last = A.at(0);
  string ans = "YES";
  for(int64_t i=1; i<N; i++){
    if(A.at(i)==last){ans = "NO"; break;}
    last = A.at(i); 
  }

  cout << ans;
}

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

 using namespace std;

 int main() {
   int N, M;

   cin >> N >> M;

   vector<vector<int>> A(N, vector<int>(M));
   vector<int> K(N);

   for (int i = 0;i < N; i++) {
     cin >> K.at(i);
     for (int j = 0; j < K.at(i); j++) {
       int tmp;
       cin >> tmp;
       A.at(i).at(tmp - 1) = 1;
     }
   }

   int ans = 0;

   for (int j = 0; j < M; j++) {
     int counter = 0;
     for (int i = 0; i < N; i++) {
       if (A.at(i).at(j) == 1) counter++;
     }
     if (counter == N) ans++;
   }

   cout << ans << endl;
}


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

#define debug(x) cout << #x << "==" << x << endl;

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

#define MAX_V 1000
#define INF INT_MAX / 2

int V, E;
bool ex_edge[MAX_V][MAX_V];

int d[MAX_V][MAX_V];
int used[MAX_V][MAX_V];          // 最短ろで使用した辺

void warshall_floyd(  ) {

  for(int a = 0; a < V; a++) {
    for(int b = 0; b < V; b++) {
      for(int c = 0; c < V; c++) {
        if( a == b || a == c || b == c) {
          continue;
        } else if( d[b][a] + d[a][c] < d[b][c] ) {
          used[b][c]--;
          d[b][c] = d[b][a] + d[a][c];
        }
      }
    }
  }
}


int main() {
  ios::sync_with_stdio(false);


  cin >> V >> E;

  fill( d[0], d[V], INF );
  for(int v=0; v < V; v++) {
    d[v][v] = 0;
  }

  for(int i = 0; i < E; i++) {
    int v, w, cost;
    cin >> v >> w >> cost;
    v--;w--;
    d[v][w] = cost;
    d[w][v] = cost;
    used[v][w] = 1;
    used[w][v] = 1;
    ex_edge[v][w] = true;
    ex_edge[w][v] = true;
  }

  warshall_floyd();

  int ans = 0;
  for(int v = 0; v < E; v++) {
    for(int w = v; w < E; w++) {
      if( ex_edge[v][w] && used[v][w] <= 0 ) {
          ans++;
      }
    }
  }
  cout << ans << "\n";

  return 0;
}


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

int main()
{
  int k, x; cin >> k >> x;
  for(int i = x+1-k; i <= x+k-1; i++)
  {
    cout << i << " ";
  }
}

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

using namespace std;

int main(){
    int numberOfElements=0;
    int numberOfOperations=0;
        
    cin>>numberOfElements;
    vector<long long int> arr(numberOfElements);
    
    long long int sum=0;

    for(int i=0; i<numberOfElements; i++){
        cin>>arr[i];
        sum=sum+arr[i];
    }
    
    cin>>numberOfOperations;
    vector<vector<int>> op(numberOfOperations, vector<int>(2,0));
    
    for(int i=0; i<numberOfOperations; i++){
        cin>>op[i][0];
        cin>>op[i][1];
    }

    sort(arr.begin(), arr.end());

    vector<long long> auxiliary(arr[numberOfElements-1]+1, 0);
    vector<long long int> output;

    for(int i=0; i<numberOfElements; i++){
        auxiliary[arr[i]-1]++;
    }

    for(int i=0; i<numberOfOperations; i++){
        if(auxiliary.size()<max(op[i][0],op[i][1])){
            auxiliary.resize(max(op[i][0],op[i][1]), 0);
        }
        sum=sum+(auxiliary[op[i][0]-1])*(op[i][1]-op[i][0]);
        auxiliary[op[i][1]-1]+=auxiliary[op[i][0]-1];
        auxiliary[op[i][0]-1]=0;
        output.push_back(sum);
    }

    for(int i=0; i<numberOfOperations; i++){
        cout<<output[i]<<" ";
    }

    return 0;
}


Measured memory_bytes: 12052
#include<cstdio>
int p[100 + 10][100 + 10];
int a[10000 + 10];
int h, w, n;

int main() {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 1;i <= n;i++)scanf("%d", &a[i]);
	int i = 1, j = 1, t = h*w, k = 1;
	while (t--) {
		p[i][j] = k;
		a[k]--;
		if (!a[k])k++;
		if (j & 1) {
			if (i == h)j++;
			else i++;
		}
		else {
			if (i == 1)j++;
			else i--;
		}
	}
	for (int i = 1;i < h;i++) {
		for (int j = 1;j < w;j++)printf("%d ", p[i][j]);
		printf("%d\n", p[i][w]);
	}
	for (int j = 1;j < w;j++)printf("%d ", p[h][j]);
	printf("%d", p[h][w]);
	return 0;
}

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

int main()
{
  int n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int cnt=0;
    for(int j=1;j<=i;j++){
      if((i%j==0&i%2))cnt++;
    }
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
<?php
/*
    Problem URL : http://abc047.contest.atcoder.jp/tasks/abc047_a
    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d %d", $A, $B, $C);

$mmax = max($A, $B, $C);
if ($mmax * 2 == $A + $B + $C) {
    echo "Yes\n";
} else {
    echo "No\n";
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

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

  long long int x[N];
  for(long long int i = 0; i < N; ++i) cin >> x[i];

  bool n[N];
  vector<long long int> l, r;
  for(long long int i = 0; i < N; ++i){
    if(x[i] < 0){
      l.emplace_back(x[i]);
      n[i] = false;
    }else{
      r.emplace_back(x[i]);
      n[i] = true;
    }
  }

  if(l.empty()){
    cout << x[K-1] << endl;
    return 0;
  }else if(r.empty()){
    reverse(x,x+N);
    cout << -x[K-1] << endl;
    return 0;
  }

  
  long long int s[N];
  for(long long int i = 0; i < l.size(); ++i){
    s[i] = l.size()-i;
  }
  for(long long int i = l.size(); i < N; ++i){
    s[i] = i-l.size()+1;
  }
  long long int ans = LONG_MAX;
  for(long long int i = 0; i < N; ++i){
    if(n[i]){
      if(K > s[i]){
        if(l.size()-K+s[i] >= 0 && l.size()-K+s[i] < N){
          ans = min(ans, x[i]-2*x[l.size()-K+s[i]]);
        }
      }else if(K == s[i]){
        ans = min(ans, x[i]);
      }
    }else{
      if(K > s[i]){
        if(l.size()+K-s[i]-1 >= 0 && l.size()+K-s[i]-1 < N){
           ans = min(ans, -x[i]+2*x[l.size()+K-s[i]-1]);
        }
      }else if(K == s[i]){
        ans = min(ans, -x[i]);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N, K;
  std::cin >> N >> K;

  // Main

  // Output
  if (K == 1)
    std::cout << 0 << std::endl;
  else
    std::cout << N - K << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int sum=0;
	if(a.at(a.size()-1)==b.at(0)){
		sum++;
	}
	if(b.at(b.size()-1)==c.at(0)){
		sum++;
	}
	
	if(sum==2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

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

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

  sort(A.begin(),A.end());
  
  bool ans=true;
  
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      ans=false;
    }
  }
  
  if(ans) cout << "YES" << endl;
  
  if(!ans) cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}

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

int main(){
  long int a,b,c;
 cin >> a >> b >> c;
 if(4*a*b<(c-a-b)*(c-a-b) && 0 < c - a - b)
 {
   cout << "Yes" << endl;
 }
 else {
   cout << "No" << endl;
 } 
 }


Measured memory_bytes: 256
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

N, W = map(int, input().split())
v = [0] * N
w = [0] * N
for i in range(N):
    v[i], w[i] = map(int, input().split())
dp = [[0] * (W + 10) for _ in range(N + 10)]
for i in range(1, W+1):
    if i >= w[0]:
        dp[1][i] = max(v[0], dp[1][i-w[0]] + v[0])
for i in range(2, N + 1):
    for j in range(1, W + 1):
        if j - w[i - 1] >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - w[i - 1]] + v[i - 1])
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[N][W])



Measured memory_bytes: 19656
n,m,x,y = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

for i in range(x,y+1):
    if all([p < i for p in a]) and all([q >=i for q in b]) and x < i <= y:
        print("No War")
        exit()
print("War")

Measured memory_bytes: 3060
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

int main(){
   ll c[4];
   rep(i, 4)cin >> c[i];
   ll a[4] = {8, 4, 2, 1};
   ll n;
   cin >> n;
   vector<P> p(4);
   rep(i, 4){
       p[i] = P(c[i] * a[i], i);
   }
   ll res = 0;
   sort(ALL(p));
   if(p[0].second == 3){
       int ii = p[1].second;
       res = c[3] * (n / 2);
     //cout << res << endl;
       n %= 2;
       if(ii == 0)res += c[ii] * n * 4;
       if(ii == 1)res += c[ii] * n * 2;
       if(ii == 2)res += c[ii] * n;
   }
   else {
       int ii = p[0].second;
       if(ii == 0)res = c[ii] * n * 4;
       if(ii == 1)res = c[ii] * n * 2;
       if(ii == 2)res = c[ii] * n;
   }
   cout << res << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
typedef long long lint;
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(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N, M;
    cin >> N >> M;
    vector<lint> A(N), B(N);
    rep(i, N) { cin >> A[i] >> B[i]; }
    vector<pair<lint, lint>> P(N);
    rep(i, N) { P[i] = make_pair(A[i], B[i]); }
    sort(all(P));
    // rep(i, N) { cout << P[i].first << " " << P[i].second << endl; }
    int i = 0;
    lint ans_price = 0;
    int ans_cnt = 0;
    while(ans_cnt < M) {
        ans_price += P[i].first * min(M - ans_cnt, (int)P[i].second);
        ans_cnt += (int)P[i].second;
        i++;
    }
    cout << ans_price << endl;
}

Measured memory_bytes: 3456