akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.IntStream;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        String s = stdin.readLine();
        long k = Long.parseLong(stdin.readLine());

        if (IntStream.range(0, s.length()).allMatch(i -> s.charAt(0) == s.charAt(i))) {
            stdout.println(s.length() * k / 2);
            return ;
        }

        char[] t = s.toCharArray();
        long c = 0;
        for (int i = 1; i < t.length; i++) {
            if (t[i - 1] == t[i]) {
                t[i] = '@';
                c++;
            }
        }

        if (s.charAt(0) == s.charAt(s.length() - 1)) {
            long a = 0;
            long b = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(0) != s.charAt(i)) break;
                a++;
            }
            for (int i = s.length() - 1; i >= 0; i--) {
                if (s.charAt(s.length() - 1) != s.charAt(i)) break;
                b++;
            }
            stdout.println(c * k - (a / 2 + b / 2 - (a + b) / 2) * (k - 1));
        } else {
            stdout.println(c * k);
        }
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}

Measured memory_bytes: 27604
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#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) {

using namespace std;

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(...);
struct debug 
{
	~debug() 
	{ 
		cerr<<endl; 
	}
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int a,b;
		cin>>a>>b;
		cout<<a*b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

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

typedef long long ll;


ll dp[210][210];
int t[210];
int a[210], b[210], c[210];

int main(){
	int d, n;
	cin>>d>>n;
	rep(i, d) cin>>t[i];
	rep(i, n) cin>>a[i]>>b[i]>>c[i];

	rep(i, 210) rep(j, 210) dp[i][j] = -1e18;
	rep(i, n) if(a[i] <= t[0] && t[0] <= b[i]) dp[0][i] = 0LL;

	REP(i, 0, d-1){
		rep(j, n) {
			if(a[j] <= t[i+1] && t[i+1] <= b[j]){
				rep(k, n) {
					dp[i+1][j] = max(dp[i+1][j], dp[i][k] + abs(c[j] - c[k]));
				}
			}
		}
	}
	
	ll ans = 0LL;
	rep(i, n) {
		ans = max(ans, dp[d-1][i]);
	}

	cout<<ans<<endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if(N == M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sat Mar 14 13:58:50 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

a, b, c = na()
d = c - a - b
if d > 0 and d * d > 4 * a * b:
    print("Yes")
else:
    print("No")

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

int main() {
	long long H, W;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) cout << 0;
	else {
		long long ans1, ans2, ans3, ans4;
		ans1 = max((H / 3) * W, (H - H / 3) * (W - W / 2)) - min((H / 3) * W, (H - H / 3) * (W / 2));
		ans2 = max((H / 3 + 1) * W, (H - H / 3 - 1) * (W - W / 2)) - min((H / 3 + 1) * W, (H - H / 3 - 1) * (W / 2));
		ans3 = max((W / 3) * H, (W - W / 3) * (H - H / 2)) - min((W / 3) * H, (W - W / 3) * (H / 2));
		ans4 = max((W / 3 + 1) * H, (W - W / 3 - 1) * (H - H / 2)) - min((W / 3 + 1) * H, (W - W / 3 - 1) * (H / 2));
		cout << min(min(H, W), min(min(ans1, ans2), min(ans3, ans4)));
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    string s, t; cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s.size() == t.size() && s == t){
        cout <<"No" <<endl;
        return 0;
    }
    rep(i, max(s.size(), t.size())){
        if(i >= s.size()){
            cout << "Yes"<<endl;
            return 0;
        }
        else if(i >= t.size()){
            cout << "No"<<endl;
            return 0;
        }
        if(s[i] - t[i] < 0){
            cout << "Yes" << endl;
            return 0;
        }
        else if(s[i] - t[i] > 0){
            cout << "No"<<endl;
            return 0;
        }
    }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

bool isorate(const vector<string>& grid, int cy, int cx) {

	P s[] = { {1,0},{-1,0},{0,1},{0,-1}};
	if (grid[cy][cx] == '.') return false;
	bool found = false;
	rep(i, 4) {
		auto x = cx + s[i].first;
		auto y = cy + s[i].second;
		if (x >= 0 && x < grid[cy].size()) {
			if (y >= 0 && y < grid.size()) {
				if (grid[y][x] == '#') {
					return false;
				}
			}
		}
	}
	return true;
}

int main(void)
{
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	rep(i, h) cin >> grid[i];
	rep(y, h) {
		rep(x, w) {
			if (isorate(grid, y, x)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
//$ node B.js < B.txt
function Main(input) {
  input = input.split('\n') // 1行目がinput[0], 2行目がinput[1], …に入る
  for(var i=0;i<input.length;i++){
    var tmp = input[i].split(' ')
    input[i] = []
    for(var ii=0;ii<tmp.length;ii++){
      input[i].push(tmp[ii])
    }
  }
  var list = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',] 
  var ans = ''
  input[1] = input[1][0].split('')
  for(var i of input[1]){
    ans += list[list.indexOf(i)+Number(input[0][0])]
  }
  

  console.log(ans)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8836
unittest
{
	assert( [ "3 2" ].parse.expand.solve == 10 );
	assert( [ "200000 200001" ].parse.expand.solve == 1 );
	assert( [ "141421 35623" ].parse.expand.solve == 220280457 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	return tuple( nk[ 0 ], nk[ 1 ] );
}

auto solve( long n, long k )
{
	const M = 10L ^^ 9 + 7;
	auto as = iota( 0, n + 1 ).array;
	auto mi = as[ 0 .. k ].sum;
	auto ma = as[ $ - k .. $ ].sum;
	auto ans = ( ma - mi + 1 ) % M;
	foreach( i; k .. n + 1 )
	{
		mi += as[ i ];
		ma += as[ $ - i - 1 ];
		ans = ( ans + ma - mi + 1 ) % M;
	}
	return ans;
}


Measured memory_bytes: 4068
#include<cstdio>
#include<cstring>
char s[105];
int main()
{
    scanf("%s", s);
    bool flag = false;
    int len = strlen(s);
    for(int i = 0; i < len; i++)
    {
        if(s[i] == 'F' && flag)
        {
            printf("Yes\n");
            return 0;
        }
        if(s[i] == 'C')
            flag = true;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=3e6+5;
int fac[N],ifac[N],n,m,res,lim;
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
int main(){
	scanf("%d%d",&n,&m);lim=m*3+n-1;
	fac[0]=ifac[0]=1;fp(i,1,lim)fac[i]=mul(fac[i-1],i);
	ifac[lim]=ksm(fac[lim],P-2);fd(i,lim-1,1)ifac[i]=mul(ifac[i+1],i+1);
	fp(i,0,m)if((3*m-i)&1^1)upd(res,mul(C(n,i),C(((3*m-i)>>1)+n-1,n-1)));
	res=dec(res,mul(n,C(m-1+n-1,n-1)));	
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 22784
n,m=map(int,input().split())
a=list(map(int,input().split()))
import math
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)
a[0]=a[0]//2
l=a[0]
cnt=0
while a[0]%2==0:
    a[0]=a[0]//2
    cnt+=1
    
for i in range(1,n):
    a[i]=a[i]//2
    l=lcm(l,a[i]) 
    x=0
    while a[i]%2==0:
        a[i]=a[i]//2
        x+=1
    if x!=cnt:
        print(0)
        exit()

print(((m//l-1)//2)+1)
    
           
    
    
    
    
    
    




Measured memory_bytes: 14244
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    int n, m, k; cin >> n >> m >> k;
    vector<int> b_val(n);
    vector<vector<int>> books(n, vector<int>(m));
    rep(i, n){
            cin >> b_val[i];
        rep(j, m){
            cin >> books[i][j];
        }
    }

        // bit 全探索
        ll res = 1e18;
    for (int bit = 0; bit < (1 << n); ++bit) {
        vector<ll> und(m, 0);
        ll money = 0;
        bool fg = true;
	//i番目に関する処理
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)){
                money += b_val[i];
                rep(j, m) und[j] += books[i][j];
            }
        }
        rep(i, m){
            if(und[i] < k){ fg = false; break;}
        }
        if(fg) chmin(res, money);
    }
    if(res == 1e18) res = -1;
    cout << res << ln;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;
const lli MOD=1e9+7;

lli ct[10];

int main(){
	lli H,W;
	int N;
	cin>>H>>W>>N;
	multiset<lli> s;
	rep(o,N){
		int a,b;
		cin>>a>>b;
      	a--;
      	b--;
		rep(i,3)rep(j,3){
			if(0<=(a-i)&&(a-i)<=H-3&&0<=(b-j)&&(b-j)<=W-3){
				lli t=(a-i)*MOD+(b-j);
				s.insert(t);
			}
		}
	}

	while(!s.empty()){
		int a=(int)s.erase(*s.begin());
		ct[a]++;
	}
	lli sum=0;
	rep1(i,9)sum+=ct[i];
	ct[0]=(H-2)*(W-2)-sum;
	rep(i,10)cout<<ct[i]<<endl;
}

Measured memory_bytes: 42496
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int x;
    cin>>x;
    int a=x/100;
    int b=x%100;
    if((b+4)/5<=a){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
program ABC106C
    implicit none
    integer(8)::K,i
    character(1)::ans
    character(100)::S
    read*,S,K

    do i=1,len_trim(S)
        if(S(i:i)=="1")then
            K=K-1
        else
            ans=S(i:i)
            exit
        end if
    end do
    if(K<1)then
        ans="1"
    end if

    print'(A)',ans
end program ABC106C

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

class hist{
public:
	int s,e;
	hist(int s,int e):s(s),e(e){};
};

bool operator < (hist a,hist b){
	if(a.s!=b.s) return a.s<b.s;
	return a.e<b.e;
}

int main()
{
	int N,M;
	while(cin>>N>>M && N!=0){
		vector<int> PC(N+1,-1);
		vector<vector<hist> > Stu(M+1);
		int r;
		cin>>r;
		for(int i=0;i<r;i++){
			int t,n,m,s;
			cin>>t>>n>>m>>s;
			if(s==0)
				Stu[m].push_back(hist(PC[n],t));
			else{
				PC[n]=t;
			}
		}
		int q;
		cin>>q;
		for(int i=0;i<q;i++){
			int s,e,m;
			cin>>s>>e>>m;
			sort(Stu[m].begin(),Stu[m].end());
			int ans=0;
			int time=s;
			for(int k=0;k<Stu[m].size();k++){
				if(Stu[m][k].e<time) continue;
				if(min(Stu[m][k].e,e)-max(time,Stu[m][k].s)<0) continue;
				ans+=min(Stu[m][k].e,e)-max(time,Stu[m][k].s);
				time=min(Stu[m][k].e,e);
			}
			cout<<ans<<endl;
		}
	}
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int pre = 0, now = 0, count = 0, maxn = 0;
	cin >> pre;
	for(int i = 1; i < n; i ++) {
		cin >> now;
		if(now <= pre) {
			count ++;
		} else {
			maxn = max(maxn, count);
			count = 0;
		}
		pre = now;
	}
	maxn = max(maxn, count);
	cout << maxn << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF=2e9;
int n,max0,min0,vis[200001];
LL ans=0;
struct data {
	int x,y;
}a[200001],b[400001];
bool cmp(data p,data q) {
	return p.x<q.x;
}
void work() {
	for (int i=1;i<=n;i++) {
		b[i*2-1].x=a[i].x;
		b[i*2].x=a[i].y;
		b[i*2-1].y=b[i*2].y=i;
	}
	sort(b+1,b+n*2+1,cmp);
	int j=0,cnt=0;
	for (int i=1;i<=n*2;i++) {
		while (j<n*2&&cnt<n) {
			j++;
			if (!vis[b[j].y]) cnt++;
			vis[b[j].y]++;
		}
		if (cnt==n) ans=min(ans,(LL)(max0-min0)*(LL)(b[j].x-b[i].x));
		if (vis[b[i].y]==1) cnt--;
		vis[b[i].y]--;
	}
}
int main() {
	scanf("%d",&n);
	max0=-INF;
	min0=INF;
	for (int i=1;i<=n;i++) {
		scanf("%d%d",&a[i].x,&a[i].y);
		max0=max(max0,max(a[i].x,a[i].y));
		min0=min(min0,min(a[i].x,a[i].y));
	}
	int nowmax=-INF,nowmin=INF;
	for (int i=1;i<=n;i++) {
		nowmin=min(nowmin,max(a[i].x,a[i].y));
		nowmax=max(nowmax,min(a[i].x,a[i].y));
	}
	ans=max0-nowmin;
	ans*=nowmax-min0;
	work();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5760
lis = [int(input()) for _ in range(5)]
jud = []
fixed = 0
fixed_index = 0
for i in range(5):
  jud.append(lis[i]%10)
for k in range(5):
  if jud[k] == 0:
    jud[k] += 9
for j in range(5):
  if min(jud) == jud[j]:
    fixed = lis[j]
    fixed_index = j
    break
for m in range(5):
  if lis[m]%10 != 0:
    lis[m] = (lis[m]//10+1)*10
lis[fixed_index] = fixed
print(sum(lis))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 62
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV], P[MV][LMV];
ll arr[MV];

void solve(int T)
{
	int n;
	ll k;
	cin>>n>>k;
	memset(P, -1, sizeof(P));
	for(int i=1;i<=n;i++)
	{
		int s;
		cin>>s;
		P[i][0] = s;
	}	
	for(int j=1;j<LMV;j++)
	{
		for(int i=1;i<=n;i++)
		{
			if(P[i][j-1] != -1)
			P[i][j] = P[P[i][j-1]][j-1];
		}		
	}	
	int s = 1;
	for(ll i=LMV-1;i>=0;i--)
	{
		if((k >= (1LL<<i)) && (P[s][i] != -1))
		{
			// cout<<s<<" "<<i<<"\n";
			s = P[s][i];
			k -= (1LL<<i);
		}	
	}
	cout<<s<<"\n";
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 52100
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = mutableMapOf<String, Int>()
    for(i in 0 until n){
        val s = readLine()!!.toString()
        if(!map.contains(s)){
            map[s] = 1
        }
    }
    println(map.keys.size)
}

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

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double t = 0;

    t = (H * 30 - 5.5 * M) * M_PI / 180;
    double cosine = cos (t);

    double x = sqrt(A * A + B * B - 2 * A * B * cosine);

    cout << setprecision (20)<< x << endl;
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
#define C getchar()
#define ll long long
#define Violet inline
//#pragma GCC optimize("O3")
using namespace std;
Violet ll read()
{
	ll x=0,l=1;char c=C;
	for (;c<'0'||c>'9';c=C) if (c=='-') l=-1;
	for (;c>='0'&&c<='9';c=C) x=x*10+c-48;
	return x*l;
}

ll n,x,ans;

int main()
{
	ans=n=read();x=read();
	ll la=x,lb=n-x;
	while (la&&lb)
		if (la>lb)
			ans+=2*lb*(ll)(la/lb),la%=lb;
		else
			ans+=2*la*(ll)(lb/la),lb%=la;
	cout<<ans-la-lb;
	return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){
int N;
cin>>N;
ll A[N][N];
rep(i,N)rep(j,N)cin>>A[i][j];


bool direct[N][N];
memset(direct,true,sizeof(direct));
for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
        for(int k=0;k<N;k++){
            
            if(A[i][j]>A[i][k]+A[k][j]){
                cout<<-1<<endl;
                return 0;
            }
            if((i==k)||(j==k))continue;
            if(A[i][j]==A[i][k]+A[k][j])direct[i][j]=false;
        }
    }
}
ll ans=0;
rep(i,N)rep(j,N)if(direct[i][j])ans+=A[i][j];
cout<<ans/2<<endl;





return 0;

}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    using ll = long long;
    using P = pair<int,int>; 
    
    int main() {
   
     int n;
     cin >> n;
     int a = n/100;
     int b = (n-a*100)/10;
     int c =n%10 ;
     if(a==7 || b == 7 || c == 7)	cout << "Yes" <<'\n';
     else cout << "No"<<'\n';
     return 0;
    }

Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.length() - 1 - i <= i)
                break;
            if (s.charAt(i) != s.charAt(s.length() - 1 - i))
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int arr[5];
    for(int i=1;i<=4;i++)arr[i]=0;
    for(int i=0;i<6;i++){
        int x;
        cin>>x;
        arr[x]++;
    }
    if(arr[4]<=2 and
       arr[1]<=2 and
       arr[2]<=2 and
       arr[3]<=2){
        cout<<"YES\n";
    }
    else cout <<"NO\n";

}


Measured memory_bytes: 256
/* ex3_2
	kanon */

#include <stdio.h>

int main(void)
{

    //与えられる値を入れる変数を宣言
    int num;

    //変数に値を入力する
    scanf("%d", &num);

    //Nの１の位の値で分岐させる
    if (num % 10 == 3)
    {
        printf("bon\n");
    }
    else if (num % 10 == 0 || num % 10 == 1 || num % 10 == 6 || num % 10 == 8)
    {
        printf("pon\n");
    }
    else
    {
        printf("hon\n");
    }

    return 0;
}


Measured memory_bytes: 1660
k = int(input())
ans = [i for i in range(1,10)]

i = 0

for i in range(k):
    now = ans[i]
    if str(now)[-1] == '0':
        ans.append(now*10)
        ans.append(now*10+1)
    elif str(now)[-1] == '9':
        ans.append(now*10+8)
        ans.append(now*10+9)
    else:
        ans.append(now*10+now%10-1)
        ans.append(now*10+now%10)
        ans.append(now*10+now%10+1)
    if len(ans) > k:
        break

print(ans[k-1])


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

typedef long long ll;
static const int MOD = 1e9+7;
static const int INF = 1<<30;

int main(){
    int N,Q;
    cin>>N;
    vector<ll> A(N);
    map<ll,ll> part;
    map<ll,ll> cnt;
    ll sum = 0;
    for(int i=0; i<N; i++){
        cin>>A[i];
        sum += A[i];
        part[A[i]] += A[i];
        cnt[A[i]]++;
    }

    cin>>Q;

    vector<ll> ans;

    for(int i=0; i<Q; i++){
        ll b,c;
        cin>>b>>c;
        sum -= part[c];
        sum -= part[b];
        cnt[c] += cnt[b];
        part[c] = c * cnt[c];
        cnt[b] = 0;
        part[b] = 0;
        sum += part[c];
        
        ans.push_back(sum);
    }

    for(auto a : ans) cout<<a<<endl;

    return 0;
}

Measured memory_bytes: 16708
mod=10**9+7

h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]

dp=[[0]*w for i in range(h)]

dp[0][0]=1

judge1=1
judge2=1
for i in range(1,h):
  if maze[i][0]=='#':
    judge1=0
  dp[i][0]=judge1
    
for i in range(1,w):
  if maze[0][i]=='#':
    judge2=0
  dp[0][i]=judge2
    
for i in range(1,h):
  for j in range(1,w):
    if maze[i][j]=='#':
      dp[i][j]=0
    else:
      dp[i][j]=dp[i-1][j]+dp[i][j-1]
      dp[i][j]%=mod
      

print(dp[-1][-1]%mod)

Measured memory_bytes: 117136
while True:
    R0, W0, C, R = map(int, input().split())
    if R0 == 0 and W0 == 0 and C == 0 and R == 0:
        break
    i = 0
    while True:
        if (R0 + i * R) // W0 >= C:
            print(i)
            break
        i += 1


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

const double pi = 3.1415926535;
double r;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r;
    cout << 2 * pi * r;
    return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;



int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	int res = 0;

	forn (i, s.size()) res += s[i] != t[i];

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    
    string s,t;
    cin>>s>>t;
    int n = s.size();
    char c[26];
    char d[26];
    for(int i=0;i<26;i++){
        c[i] = '0';
        d[i] = '0';
    }
    for(int i=0;i<n;i++){
        if(c[s[i]-'a'] == '0')c[s[i]-'a'] = t[i];
        if(d[t[i]-'a'] == '0')d[t[i]-'a'] = s[i];
        if(c[s[i]-'a'] != t[i] || d[t[i]-'a'] != s[i]){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);

	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];

	c = a;
	int d, e;
	int cnt = 0;
	sort(ALL(c));
	do{
		cnt++;
		if (a == c)d = cnt;
		if (b == c)e = cnt;

	} while (next_permutation(ALL(c)));

	cout << abs(d - e) << endl;

}


Measured memory_bytes: 256
// Aizu 1601: Short Phrase
// 2017.9.21 bal4u@uu

#include <stdio.h>
#include <string.h>

int w[42];
int a[5] = { 5,7,5,7,7 };

int main()
{
	int n, i, j, k, ans, s;
	char t[15];

	while (scanf("%d", &n) && n) {
		for (ans = 0, i = 0; i < n; i++) scanf("%s", t), w[i] = strlen(t);
		for (i = 0; i < n; i++) for (k = s = 0, j = i; j < n; j++) {
			s += w[j];
			if (s == a[k]) {
				s = 0;
				if (++k == 5) { ans = i+1; goto Done; }
			} else if (s > a[k]) break;
		}
Done:	printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1824
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

# 多次元配列
# dp = [[0] * 3 for _ in range(5)]

# 入力を受け取る
print(int(input()) ** 2)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n;
   cin>>n;
   
   vector<int> x(n);

   rep(i,n){
      cin>>x[i];
   }
   vector<int> y=x;
   sort(x.begin(),x.end());

   int l=n/2-1;
   int r=n/2;

   rep(i,n){
      if(y[i]<=x[l]) cout<<x[r]<<endl;
      else cout<<x[l]<<endl;
   }
   return 0;
}


Measured memory_bytes: 4820
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	LL a, b, v, w, t;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	
	if(a < b) {
		LL db = b + t*w;
		LL da = a + t*v;
		if(da >= db) cout<<"YES"<<en;
		else cout<<"NO"<<en;
	} else {
		LL db = b - t*w;
		LL da = a - t*v;
		if(da <= db) cout<<"YES"<<en;
		else cout<<"NO"<<en;
	}
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] l = new int[2*n];
      for(int i = 0;i < n*2;i++)l[i]=sc.nextInt();
      Arrays.sort(l);
      int sum = 0;
      for(int i = 0;i < 2*n;i+=2)sum+=l[i];
      System.out.println(sum);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include "bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a-1;i>=0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7

int main() {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll white = 0, black = 0;
    REP(i, n) {
        if(s[i] == '#')black++;
        if(s[i] == '.')white++;
    }
    ll rw = white, lb = 0;
    ll ans = rw + lb;
    REP(i, n){
        if(s[i] == '#')lb++;
        if(s[i] == '.')rw--;
        ans = min(ans, lb + rw);
    }
    print(ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  mint ans = 1;
  vector<int> RGB(3);
  rep(i, N) {
    ll temp = 0;
    int ind;
    rep(j, 3) {
      if (A[i] == RGB[j]) {
        temp++;
        ind = j;
      }
    }
    ans *= temp;
    RGB[ind]++;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    def main():
        
        N,K=map(int,input().split())
        D=set(map(int,input().split()))

        L={i for i in range(10)}
        U=L-D
        while True:

            sn = str(N)
            ln = len(sn)

            for i in range(ln):
                if int(sn[i]) not in U:
                    N+=1
                    break
                elif i==ln-1:
                    return int(N)
    print(main())



resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int x;cin >> x;
  if(x == 3 || x == 5 || x == 7){
    say("YES");
  }else{
    say("NO");
  }
}

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


if n == 2:
    print(abs(a[0]-a[1]))
else:
    goukei = sum(a)
    x = [0]*n
    x[0] = a[0]
    ans = 10**11
    for i in range(1, n-1):
        x[i] = x[i-1] + a[i]
        y = goukei - x[i]
        ans = min(ans, abs(x[i]-y))
    print(ans)

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

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

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

int n;

void dfs(string s, char mx)
{
  if(s.length() == n){
    cout << s << endl;
  }else {
    for (char c = 'a'; c <= mx; c++){
      dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
    }
  }
}

int main()
{
  cin >> n;
  dfs("", 'a');
  return 0;
}

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

ans = [0] * (N+1)

for j in range(K):
    ans = [0] * (N+1)
    for i in range(N):
        L = max(0, i-A[i])
        R = min(N, i+A[i]+1)
        ans[L] += 1
        ans[R] -= 1
    for i in range(1, N+1):
        ans[i] += ans[i-1]
    issame = True
    for i in range(N):
        if i != 0:
            if ans[i-1] != N or ans[i-1] != ans[i]:
                issame = False
        A[i] = ans[i]
    if issame:
        break

for i in range(N):
    print(ans[i], end=' ')

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


int main() {
  int A,B;
  cin>>A>>B;

  int dist,dist2;
  int P;
  bool can=false;

  for(int K=0;K<1000000000;K++){
    dist=abs(A-K);
    dist2=abs(B-K);

    if(dist==dist2){
      can=true;
      P=K;
      break;
    }
  }

  if(can){
        cout<<P<<endl;
    }else{
    cout<<"IMPOSSIBLE"<<endl;
  }

}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a<10 and b<10) {
        cout << a*b << endl;
    }else {
        cout << "-1" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
// x番の組織が親組織に提出する枚数を返す
// childrenは組織の関係を表す2次元配列(参照渡し)
int count_report_num(vector<vector<int>> &children, int x) {
  // ベースケース
  if (children.at(x).size() == 0) {
    // 子組織から受け取ることは無いので0枚であることが確定している
    return 1;
  }
 
  // 再帰ステップ
  int sum = 0;
  for (int c : children.at(x)) {
      sum += 1;
    //sum += count_report_num(children, c);
  }
  sum += 1;  // x番の組織の報告書の枚数(1枚)を足す
  return sum;
}
 
// これ以降の行は変更しなくてよい
 
int main() {
  int N;
  cin >> N;
 
  vector<int> p(N);  // 各組織の親組織を示す配列
  p.at(0) = -1;  // 0番組織の親組織は存在しないので-1を入れておく
  for (int i = 1; i < N; i++) {
    cin >> p.at(i);
    p.at(i)--;
  }
 
  // 組織の関係から2次元配列を作る
  vector<vector<int>> children(N);  // ある組織の子組織の番号一覧
  for (int i = 1; i < N; i++) {
    int parent = p.at(i);  // i番の親組織の番号
    children.at(parent).push_back(i);  // parentの子組織一覧にi番を追加
  }
 
  // 各組織について、答えを出力
  for (int i = 0; i < N; i++) {
    cout << count_report_num(children, i)-1 << endl;
  }
}

Measured memory_bytes: 14824
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var firstLine = cin.ReadLine.Split(' ');
            var N = int.Parse(firstLine[0]);
            var M = int.Parse(firstLine[1]);

            
            List<string> result = new List<string>();
            List<string> minusList = new List<string>();
            for (int i = 0; i < N; i++)
            {
                var lineInfo = cin.ReadLine.Split(' ');
                for (int j = 1; j < lineInfo.Length; j++)
                {
                    if (i == 0)
                    {
                        result.Add(lineInfo[j]);
                    }
                    else
                    {
                        minusList.Add(lineInfo[j]);
                    }
                }
                if (i != 0)
                {
                    result = result.Intersect<string>(minusList).ToList();
                    if (!result.Any())
                    {
                        Console.Write("0");
                        return;
                    }
                    minusList = new List<string>();
                }

            }
            Console.Write(result.Count());
        }
    }
    public class deci
    {
        public bool IsFinish { get; set; } = false;
        public int Len { get; set; }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13404
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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


int main() {
    int N;
    cin >> N;
    vector<int> A(N);

    int num_minus = 0;
    int64_t sum = 0;
    
    rep(i, N) { 
        cin >> A[i];
        if(A[i] < 0) {
            A[i] = A[i] * -1;
            num_minus++;
        }
        sum += A[i];
    }

    if(num_minus % 2 == 0) {
       cout << sum << endl; 
    } else {
        sort(A.begin(), A.end());
        cout << sum - A[0]*2 << endl;
    }


    return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
    
int main(){
	int n;
    cin>>n;
    int ans=0;
    int flag=0;
    for(int i=1;i<n+1;i++){
        int k=i*1.08;
     if(k==n){
         ans=i;
         flag=1;
         break;
     }   
    }
    if(flag==1) OUT(ans);
    else cout<<":("<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
p, y = Array.new(m) { gets.split.map(&:to_i) }.transpose
h = Hash.new(0)
ret = {}

p.zip(y).sort.each do |p, y|
  h[p] += 1
  ret[y] = format('%06d', p) + format('%06d', h[p])
end

y.each { |e| puts ret[e] }

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

int main() {
	long long int i,n,a[10000],all;
	while (1) {
		all = 0;
		cin >> n;
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		for (i = 0; i < n - 1; i++) {
			all += a[i] * (n - i-1);
		}
		cout << all << endl;
	}
	return 0;
}

Measured memory_bytes: 3172