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

int main(){
  string N;
  cin >> N;
  int ans=0;
  int s=N.size();
  for(int i=0;i<=s;i++){
    int cnt=0;
    for(int j=0;j<i;j++){cnt+=N[j]-'0';}
    if(i==s){ans=max(ans,cnt); continue;}
    int k=N[i]-'0'-1;
    if(k==-1)continue;
    cnt+=k;
    for(int j=i+1;j<s;j++){cnt+=9;}
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner s = new Scanner(System.in);
          int x = Integer.parseInt(s.next());
          int y = Integer.parseInt(s.next());
      	  int z = Integer.parseInt(s.next());
      	
      	System.out.println(z + " " + x + " " + y);
    }
}

Measured memory_bytes: 21844
N,W = gets.split.map(&:to_i)
value = Array.new(N)
weight = Array.new(N)

N.times {|i| value[i], weight[i] = gets.split.map(&:to_i) } 

dp = Array.new(N+1) {Array.new(W+1){0}}

(0...N).each do |i|
  (0..W).each do |w|
    if w >= weight[i]
      dp[i+1][w] = [dp[i][w-weight[i]] + value[i], dp[i][w]].max
    else
      # w よりも weight[i] が大きいとき、品物iが選ばれていることはありえない
      dp[i+1][w] = dp[i][w]
    end
  end
end

puts dp[N][W]



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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

void solve(){
    int n;
    cin >> n;
    if(n>=30){
        cout<<"Yes";line
    }
    else{
        cout << "No";line
    }
}
int main(){
	fast
	int t=1;
	//cin >> t;
	while(t--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3648
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: i32,
    k: i32,
  }
  if k == 1 {
    println!("{}", 0);
  } else {
    println!("{}", n - k);
  }
}


Measured memory_bytes: 4352
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=1e3+5;
char s[maxn][maxn];
int ans[maxn][maxn],vis[maxn][maxn],n,m,fx,fy,tx,ty;
int dir[4][2]={1,0,-1,0,0,1,0,-1};

struct node
{
    int x,y,step=0;
    node(int x=0,int y=0,int step=0):x(x),y(y),step(step) {}
};
deque<node> Q;

int main()
{
    n=read(),m=read();
    fx=read(),fy=read();
    tx=read(),ty=read();
    REP(i,1,n) scanf("%s",s[i]+1);
    REP(i,1,n) REP(j,1,m) ans[i][j]=-1;
    Q.push_back(node(fx,fy,0));
    while(!Q.empty())
    {
        node nd=Q.front(); Q.pop_front();
        int x=nd.x,y=nd.y,step=nd.step;
        if(vis[x][y]) continue;
        //cout<<x<<' '<<y<<endl;
        vis[x][y]=1;
        ans[x][y]=step;
        for(int i=0;i<4;i++)
        {
            int xx=x+dir[i][0],yy=y+dir[i][1];
            if(xx>0 && xx<=n && yy>0 && yy<=m && !vis[xx][yy] && s[xx][yy]=='.')
                Q.push_front(node({xx,yy,step}));
        }
        for(int xx=x-2;xx<=x+2;xx++)
            for(int yy=y-2;yy<=y+2;yy++)
            {
                if(xx>0 && xx<=n && yy>0 && yy<=m && !vis[xx][yy] && s[xx][yy]=='.')
                    Q.push_back((node){xx,yy,step+1});
            }
    }
    if(ans[tx][ty]<0) puts("-1");
    else printf("%d\n",ans[tx][ty]);

    return 0;
}

Measured memory_bytes: 13088
#include <algorithm>
#include <iostream>
#include <map>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
 /////////////////////////////////////////////////////
bool d[50][50]={};




int dfs(int v,int n,bool visited[]){
	bool allvisited = true;

	REP(i,n){
		if (visited[i] == false){
			allvisited = false;
		}
	}
	
	if (allvisited == true) {
		return 1;
	}
	
	int ret = 0;
		
	REP(j,n){
		if(d[v][j]==false) continue;
		if(visited[j]) continue;

			visited[j] = true;
			ret += dfs(j,n,visited);
			visited[j] = false;
	}
	
	return ret;
}

int main() {
	int n,m;
	SCD(n);
	SCD(m);


	REP(i,m){
		int a,b;
		SCD(a);
		SCD(b);
		a--; b--;
		d[a][b] = true; d[b][a] = true;
	}
	
	bool visited[n];
	
	REP(i,n){visited[i]=false;}
	
	visited[0] = true;
	int ans = 0;
	ans = dfs(0,n,visited);
	PRINTD(ans);
	return 0;
}
	


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

int main(){
  string s;
  cin >> s;
  int la = 0;
  int rz = s.size()-1;
  while(true){
    if(s.at(la) == 'A'){
      break;
    }else{
      la++;
    }
  }
  while(true){
    if(s.at(rz) == 'Z'){
      break;
    }else{
      rz--;
    }
  }
  cout << rz - la + 1 << endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, 0, N) cin >> a[i];
  int ans = 0;
  rep(i, 0, N) if(a[a[i] - 1] == i + 1) ans++;
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
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 mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

bool Check(string s) {
	bool flag = true;
	int size = sz(s);
	rep(i, size / 2) {
		if (s[i] != s[size - i - 1])flag = false;
	}
	return flag;
}

int main() {
	int ans = 0;
	string s;
	while (cin >> s) {
		ans += Check(s);
	}
	Cout(ans);
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main(){
    set<int> a;
    rep(i,3){
        int n; cin >> n;
        a.insert(n);
    }
    print(a.size());
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
  int N;
  std::string S;
  std::cin >> N >> S;
  char now = '0';
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (S[i] == 'A') now = 'A';
    else if (now == 'A' && S[i] == 'B') now = 'B';
    else if (now == 'B' && S[i] == 'C') now = 'C';
    else now = '0';
    if (now == 'C')
    {
      ans++;
      now = '0';
    }
    // std::cout << "S[i] = " << S[i] << ", now = " << now << ", ans = " << ans << std::endl;
  }
  std::cout << ans << std::endl;
}


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder 
//begineer 140
//b

int n;
int seq[100];
int sat[100];
int extra_sat[100];

int main()
{
	cin>>n;

	int temp;

	FOR0(i, n) {cin>>temp; seq[i]=--temp;}
	FOR0(i, n) cin>>sat[i];
	FOR0(i, n-1) cin>>extra_sat[i];

	int ans = 0;

	ans+=sat[seq[0]];

	for (int i = 1; i < n; ++i)
	{
		if(seq[i]==seq[i-1]+1)
		{
			ans+=extra_sat[seq[i-1]];
		}
		ans+=sat[seq[i]];
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a,b;

int main(){
	cin>>n>>m;
	a=b=vi(m);
	for(int i=0;i<m;i++) cin>>a[i]>>b[i];
	vl dp(n+1),DP(n+1);
	dp[1]++;
	DP[1]++;
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){
			(dp[i]+=DP[max(0,i-a[j])]-DP[max(0,i-b[j]-1)]+mod)%=mod;
		}
		DP[i]=(dp[i]+DP[i-1])%mod;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 6396
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
 
    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)
 
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)



N = int(input())
A = list(map(int,input().split()))
A.sort()
M = pow(10,6)+ 100
Tree = BIT(M)
for x in A:
  Tree.add(x,1)
ans = 0
for i in range(N):
  for j in range(i+1,N):
    x = A[i]; y = A[j]
    Tree.add(x,-1);Tree.add(y,-1)
    MIN = abs(x-y)+1; MAX = (x+y)-1
    #print(x,y,MIN,MAX)
    ans += Tree.get(MIN,MAX)
    Tree.add(x,1);Tree.add(y,1)
    #print(ans)
print(ans//3)

Measured memory_bytes: 83368
#include <iostream>
#include <string>

using namespace std;

int main(){
	double m[] = {70.0,55.0,50.0,43.0,40.0,37.5,35.5};
	double mm[] = {148.0,116.0,105.0,89.0,83.0,77.0,71.0};
	string award[] = {"NA","E","D","C","B","A","AA","AAA"};
	double t,tt;
	
	while(cin >> t >> tt){
	int g1,g2,min;
	if(m[0] <= t) g1 = -1;
	else {
		for(int i=0;i < 6;i++){
			if(m[i] > t && m[i+1] <= t) g1 = i;
		}
		if(t < m[6]) g1 =6;
	}
	if(mm[0] <= tt) g2 = -1;
	else {
		for(int i=0;i < 6;i++){
			if(mm[i] > tt && mm[i+1] <= tt) g2 = i;
		}
		if(tt < mm[6]) g2 =6;
	}
	if(g1 > g2) min = g2;
	else min = g1;
	cout << award[min+1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


len_A = int(input())
A = list(map(int,input().split()))

len_B = int(input())
B = list(map(int,input().split()))

B_Bigger = False
for i in range(min(len_A,len_B)):
    if A[i] != B[i]:
        B_Bigger = B[i] > A[i]
        break
    if i == len_A-1 and i != len_B-1:
        B_Bigger = True

if B_Bigger == True:
    print("1")
else:
    print("0")



Measured memory_bytes: 6468
a=[list(map(int,input().split()))for i in range(3)]
s=a[0]+a[1]+a[2]
def f(i):
    return s[i]+s[i+2]-s[i-1]-s[i+3]
if f(1)==f(2)==f(4)==f(5)==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/**
 *   author: sahushivam
 *   created: 16 February 2020 (Sunday)  17:39:53
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if((a[i]%3!=0) && (a[i]%5!=0)){
                cout<<"DENIED\n";   
                return;
            }

        }
    }
    cout<<"APPROVED\n";
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    if (a <= b)
        cout << a << endl;
    else
        cout << a - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int a, b, c, k;
signed main() {
	cin >> a >> b >> c >> k;
	if (k % 2 == 1) {
		cout << b - a << endl;
	}
	else {
		cout << a - b << endl;
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
int a[200005];
int b[200005];
int main(void){
	int N;
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> a[i];
	}
	ll ans = 0;
	for(int i=N;i>=1;i--){
		int c = 0;//今までの箱に入っているボールの合計数
		int t = i;//tは現在見ている番号
		while(t<=N){
			c += b[t];
			t+=i;
		}
		if(c%2==a[i])b[i] = 0;
		else {
			b[i] = 1;
			ans++;
		}
	}
	cout << ans << endl;
	for(int i=1;i<=N;i++){
		if(b[i]==1){
			cout << i <<" ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)

int main(void){
    int n,m;
    cin >> n >> m;
    if(n%2 == 1&&m%2 == 1)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let n = it.next().unwrap();

    println!("{}", count(n, 0));
}

fn count(n: usize, x: usize) -> usize {
    if n < x {
        return 0;
    }

    let mut ret = 1;
    for c in "357".chars() {
        if !x.to_string().contains(c) {
            ret = 0;
            break;
        }
    }
    
    for c in "357".chars() {
        let next = x * 10 + (c as usize - '0' as usize);
        ret += count(n, next);
    }
    
    ret
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  string backk = "";
  string frontt = "";
  bool front = true;
  for(int que = 0;que<q;que++){
    int t;
    cin >> t;

    if(t==1){
      front = !front;
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(front){
        if(f==1){
          frontt = c + frontt;
        }else{
          backk += c;
        }
      }else{
        if(f==1){
          backk += c;
        }else{
          frontt = c + frontt;
        }
      }
    }
  }
  s = frontt + s + backk;
  if(!front)reverse(s.begin(),s.end());
  cout<<s<<endl;
}


Measured memory_bytes: 1360
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      char[][] grid = new char[h][w];
      for(int i = 0; i < h; i++)
        grid[i] = sc.next().toCharArray();

      int maxDist = Integer.MIN_VALUE; 
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
          if(grid[i][j] == '#') continue;
          maxDist = Math.max(maxDist, bfs(grid, i, j));
        }
      }
      System.out.println(maxDist);
  }

  private static int bfs(char[][] grid, int row, int col) {
      int rows = grid.length;
      int cols = grid[row].length;

      Queue<Integer> queue = new LinkedList<>();
      queue.offer(row * cols + col);
      Set<Integer> visited = new HashSet<>();
      visited.add(row * cols + col);
      int step = 0;
      int[] rowsArr = new int[]{-1, 1, 0, 0};
      int[] colsArr = new int[]{0, 0, -1, 1};
      while(!queue.isEmpty()) {
          int size = queue.size();
          for(int i = 0; i < size; i++) {
              int idx = queue.poll();
              int r = idx / cols;
              int c = idx % cols;
              for(int d = 0; d < rowsArr.length; d++) {
                int nextRow = r + rowsArr[d];
                int nextCol = c + colsArr[d];
                if(!isValid(grid, visited, nextRow, nextCol)) continue;
                queue.offer(nextRow * cols + nextCol);
                visited.add(nextRow * cols + nextCol);
              }
          }
          if(!queue.isEmpty())
            step++; 
      }
      return step;
  }

  private static boolean isValid(char[][] grid, Set<Integer> visited, int row, int col) {
    if(row < 0 || row >= grid.length || col < 0 || col >= grid[row].length || grid[row][col] == '#' || visited.contains(row * grid[row].length + col))
      return false;
    return true;
  }
}

Measured memory_bytes: 39308
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  int ans=inf;
  rep(i,n){
    int a; cin>>a;
    int cnt=0;
    while(a%2==0){
      a/=2;
      cnt++;
    }
    ans = min(ans,cnt);
  }
  
  cout << ans << endl;
  return 0;
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll A1, A2, A3;
    scanf("%lld %lld %lld", &A1, &A2, &A3);
    if ( A1 + A2 + A3 >= 22 ) printf("bust\n");
    else printf("win\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
  char ha[1<<21],k[256];
int main(int argc,char *argv[]){
  int flg;
  int val,s,t;
  char c;
  k['T'] = 1;
  k['G'] = 2;
  k['C'] = 3;
  k['A'] = 4;
    
  scanf("%d", &val);
  getchar();
  while (val--) {
    s = 0;
    t = 1;
    flg = ( c = getchar() ) == 'i';
    while ( ( c = getchar() ) != ' ' );
    while ( ( c = k[getchar()] ) != 0 ) {
      s += c * t;
      t *= 4;
    }
    if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
  }
  return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

	int n,m,d[112345],u[212345],v[212345];
	vector<P> g[112345];

	queue<int> qq;

	int c[112345],res[212345];
	bool used[212345];
	bool usedp[112345];

	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>d[i+1],c[i+1]=2,usedp[i+1]=false;
	for(int i=0;i<m;i++)
	{
		cin>>u[i]>>v[i];
		g[u[i]].push_back({v[i],i});
		g[v[i]].push_back({u[i],i});

		if(d[u[i]]==d[v[i]])
		{
			qq.push(i);
		}

		res[i]=1e9+10;
		used[i]=false;

	}

	if(qq.size()==0)
	{
		cout<<-1<<endl;
		return 0;
	}

	queue<int> q;

	while(qq.size())
	{
		int pp=qq.front();
		qq.pop();

		if(c[u[pp]]!=2||c[v[pp]]!=2) continue;

		c[u[pp]]=0;
		c[v[pp]]=1;
		res[pp]=d[u[pp]];
		q.push(pp);

		while(q.size())
		{
			int p=q.front();
			q.pop();

			if(used[p]) continue;
			used[p]=true;

			int arr[2]={u[p],v[p]};

			for(int j=0;j<2;j++)
			{
				int cur=arr[j];
				if(usedp[cur]) continue;
				usedp[cur]=true;
				for(P i:g[cur])
				{
					int e=i.second;
					int k=i.first;
					if(res[e]!=1e9+10) continue;

					if(c[k]!=2)
					{
						res[e]=max(d[cur],d[k]);
						continue;
					}

					if(d[cur]==d[k])
					{
						c[k]=1-c[cur];
						if(used[e]) continue;
						res[e]=d[cur];

						q.push(e);

						continue;
					}

					if(d[cur]>d[k])
					{
						res[e]=d[cur];

						continue;
					}

					if(d[cur]<d[k])
					{
						c[k]=c[cur];
						if(used[e]) continue;
						res[e]=d[k]-d[cur];

						q.push(e);

						continue;
					}
				}
			}

		}
	}

	for(int i=1;i<=n;i++)
	{
		if(c[i]==2)
		{
			cout<<-1<<endl;
			return 0;
		}
	}

	for(int i=1;i<=n;i++)
		cout<<(c[i]==0?"B":"W");
	cout<<endl;
	for(int i=0;i<m;i++) cout<<res[i]<<endl;


	return 0;
}


Measured memory_bytes: 14592
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++) 

using namespace std;

int main() {
    int k, n;
    cin >> k >> n;
    int A[n];
    rep(i, n) cin >> A[i];
    
    int min = A[n-1] - A[0];

    rep(i, n-1) {
        if (min > (k - (A[i+1]-A[i]))) {
            min = k - (A[i+1]-A[i]);
        }
    }
    if (min > (k - ((A[0] - A[n-1])))) {
        min = k - (A[0] - A[n-1]);
    }
    for (int i = 1; i < n-1; i++) {
        if (min > (k - (A[i]-A[i-1]))) {
            min = k - (A[i]-A[i-1]);
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		for (int i = 2; i < S.length(); i += 2) {
			String front = S.substring(0, S.length()/2-i/2);
			String back = S.substring(S.length()/2-i/2, S.length()-i);
			if (front.equals(back)) {
				String ans = front + back;
				System.out.println(ans.length());
				break;
			}
		}
	}
}

Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define FST first
#define SND second

#define MAX_N   (100)                  // 10^5
#define MAX_S   (100)                  // 10^5
// #define MAX_N   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

int N, S[MAX_N];

void solve() {
  ll sum = 0;
  for (int i = 0; i < N; i++) sum += S[i];

  ll ans = 0;
  if (sum % 10 != 0) {
    ans = sum;
  } else {
    sort(S, S + N);
    for (int i = 0; i < N; i++) {
      if (S[i] % 10 != 0) {
        ans = sum - S[i];
        break;
      }
    }
  }

  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
//# include <atcoder/all>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define rsort(x) (x).rbegin(), (x).rend()
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

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

    map<ll, ll> mp;
    for (auto a : A) ++mp[a];

    vector<ll> x, y;
    for (auto smap : mp) {
        if (2 <= smap.second) x.emplace_back(smap.first);
        if (4 <= smap.second) y.emplace_back(smap.first);
    }
    sort(all(x), greater<ll>()), sort(all(y), greater<ll>());

    ll ans = 0;
    if (2 <= len(x)) ans = x[0] * x[1];
    if (len(y)) ans = max(ans, y[0] * y[0]);
    
    cout << ans << endl;
}

Measured memory_bytes: 10284
import sys
A,B = [int(n) for n in input().split()]
# N = int(input())
# A = [0]*N
# for i in range(N):
#     A[i] = int(input())
# S = str(input())
# T = str(input())
if(B%A == 0):
    print(A+B)
else:
    print(B-A)


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    if (b == c)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  } else if (b == c) {
    cout << "Yes" << endl;
  } else if (a == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

ll gcd(ll a, ll b){
  return b != 0 ? gcd(b, a % b) : a;
}

struct UnionFind{
  vector<ll> par;
  
  UnionFind(ll n) : par(n, -1){}
  void init(ll n){par.assign(n, -1);}
  
  ll root(ll x){
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  
  bool issame(ll x, ll y){
    return root(x) == root(y);
  }
  
  bool merge(ll x, ll y){
    x = root(x); y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x) {
    return -par[root(x)];
  }
};

int main(){
  kyopro;
  ll N, M;
  cin >> N >> M;
  vector<ll> X(M), Y(M);
  rep(i, 0, M){
    ll trash;
    cin >> X.at(i) >> Y.at(i) >> trash;
    X.at(i)--;
    Y.at(i)--;
  }
  UnionFind ok(N);
  rep(i, 0, M){
    ok.merge(X.at(i), Y.at(i));
  }
  set<ll> numofroot;
  rep(i, 0, N){
    numofroot.insert(ok.root(i));
  }
  cout << numofroot.size() << rt;
}

Measured memory_bytes: 7296
#include <iostream>
using namespace std;
int main() {
	int n,k;
	cin>>n;
	int *a=new int[n+1]();
	int *b=new int[n+1]();
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	int l=1;
	for(int i=n; i>=1;) {
		if(a[i]==i) {
			b[l]=a[i];
			l++;
			k++;
			for(int j=i; j<=n; j++) {
				a[j]=a[j+1];
			}
			i=n;
		}
		i--;
	}
	if(k==n) {
		for(int i=n; i>=1; i--) {
			cout<<b[i]<<endl;
		}
	}		else {
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import math

N = int(input())

if N==0:
  r=0
elif N%2==1:
  r=0
else:
  rep = int(math.floor(math.log(N,5)))
  r=0
  for i in range(rep):
    q = 5**(i+1)
    if (N//q)%2==0:
      w = (N//q)//2
    else :
      w = ((N-1)//q)//2
    r+=w


print(r)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input();
		if(p[0][p[0].Length - 1] == p[1][0] && p[1][p[1].Length - 1] == p[2][0])
		{
			Console.WriteLine("YES");
		}
		else
		{
			Console.WriteLine("NO");
		}
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        a: usize,
        b: usize,
        n: usize,
    }

    let x = std::cmp::min(b - 1, n);

    let result = a * x / b - a * (x / b);

    echo!(result);
}


Measured memory_bytes: 2112
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

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

    

    

    
}  
/*
*/


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

#define int long long
#define double long double

struct line{
    double a, b;
};

vector< line > s;

double intersect(line a, line b){
    return (a.b-b.b)/(b.a-a.a);
}

double query(int x){
    int left = 0;
    int right = s.size()-1;

    while(left < right){
        int mid = (left+right)/2;

        if(s[mid].a * x + s[mid].b < s[mid+1].a * x + s[mid+1].b){
            right = mid;
        }else{
            left = mid+1;
        }
    }
    return s[left].a * x + s[left].b;
}

void add(line L){
    while(s.size() >= 2 && intersect(s[s.size()-2], s.back()) >= intersect(s[s.size()-2], L)){
        s.pop_back();
    }
    s.push_back(L);
}

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

    int n, c;
    cin >> n >> c;

    vector< int > v(n);

    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    vector< int > dp(n);

    add({-2*v[0],v[0]*v[0]});

    dp[0] = 0;

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

        dp[i] = c + v[i]*v[i];
        dp[i] += query(v[i]);

        //cout << "DP " << i << ' ' << "Query " << query(v[i]) << " is equal to " << dp[i] << endl;

        line L = {-2*v[i],dp[i]+v[i]*v[i]};

        add(L);
    }

    cout << dp.back() << endl;

}


Measured memory_bytes: 13548
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    a>0?cout<<"Positive":(a==0||(a<0&&b>0)?cout<<"Zero":(((abs(b)-abs(a))%2!=0?cout<<"Positive":cout<<"Negative")));
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, c;
	int ans;
	
	scanf("%d%d%d",&a,&b,&c);
	
	if (a == b) 
		ans = c;
	else if (a == c) 
		ans = b;
	else 
		ans = a;
		
	printf("%d",ans);
	
	return 0;
}
	

Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> [Int16] -> Int32
solve n hs = fst $ fst dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp = foldl'
    (\((!dp1, !dp2), (!x, !y)) (!i, !v) -> if i == 0
      then ((0, dp1), (v, x))
      else if i == 1
        then ((dp1 + abs (fromIntegral $ v - x), dp1), (v, x))
        else
          ( ( min (dp1 + abs (fromIntegral $ v - x))
                  (dp2 + abs (fromIntegral $ v - y))
            , dp1
            )
          , (v, x)
          )
    )
    ((-1, -1), (-1, -1))
    (zip ([0 ..] :: [Int]) hs)

main = do
  let sillyTail b | B.null b  = b
                  | otherwise = B.tail b
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt b
        | B.null b = Nothing
        | otherwise = fmap (first fromIntegral . second sillyTail) $ B.readInt b

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- unfoldr readInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 1916
from itertools import combinations

N,M,X = map(int,input().split())

all_text = [list(map(int,input().split())) for i in range(N)]

array = [i for i in range(N)]
comb = []

for i in range(N):
    r = list(map(list,list(combinations(array,i+1))))
    comb.extend(r)

ans = []

for i in comb:
    check = [0 for i in range(M)]
    answer = [0 for i in range(M+1)]
    for j in i:
        for m in range(len(all_text[j])):
            answer[m] += all_text[j][m]
            if m>=1 and answer[m] >= X:
                check[m-1] = 1
    if sum(check) >= M:
        ans.append(answer[0])

if not ans:
    print(-1)
    exit()

ans.sort()
print(ans[0])


Measured memory_bytes: 10012
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int N;
    cin>>N;
    long long int A[N],B[N],C[N];
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>C[i];
    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);
    long long int ans=0;
    rep(i,N){
        long long int a = lower_bound(A,A+N,B[i]) - A;
        long long int c = upper_bound(C,C+N,B[i]) - C;
        ans += a*(N-c);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5968
def isPalindrome(S):
    
    palindrome = True
    for i in range(len(S)//2):
        if S[i] != S[-1-i]:
            palindrome = False
    
    return palindrome
    
    

S = input()

allS = isPalindrome(S)
formerS = isPalindrome(S[:len(S)//2])
latterS = isPalindrome(S[len(S)//2+1:])

if allS and formerS and latterS:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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 <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    vector<int> s;
    for (int i = 1; i <= min(a, b); i++) {
        if (a % i == 0 && b % i == 0)
            s.push_back(i);
    }
    cout << s[s.size()-k] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	vi d(n);
	rep(i,n) cin>>d[i];
	sort(all(d));
	int ans=d[n/2]-d[n/2-1];
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 4048
#include <stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  int a[n];
  int i, j;
  int count = 0;
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  while(1){
    for(i = 0; i < n; i++){
      if(a[i] % 2 != 0){
        printf("%d\n", count);
        return 0;
      }
      a[i] /= 2;
    }
    count++;
  }
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	//freopen("test", "r", stdin);
	ios::sync_with_stdio(false);
	int X;
	cin >> X;
	int have = X / 100, need = X % 100;
	int flag = 1;
	if(need > 5 * have){
		flag = 0;	
	}	
	cout << flag << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N, T;
    cin >> N >>T;
    ll t[N];
    ll ans=0;
    rep(i,N) cin >> t[i];
    int tmp=0;
    for(int i=1; i<N; i++){
        if(T<(t[i]-t[i-1])){
            ans+=T;
        }else{
            ans+=(t[i]-t[i-1]);
        }
        //cout << ans <<endl;
    }
    ans+=T;
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 1792
def main():
    a, b, k = map(int, input().split())
    print(solve(a, b, k))

def solve(a, b, k):
    n = 0
    for i in range(100, 0, -1):
        if a % i == 0 and b % i == 0:
            n += 1
            if n == k:
                return i

main()


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    int MOD = 100000;

    while (true) {
        int N, M, S;
        cin >> N >> M >> S;
        if (N + M + S == 0) {
            break;
        }

        VV<LL> dp(N * N + 2, V<LL>(S + 1, 0));
        dp[0][0] = 1;

        FOR(i, 1, M + 1) {
            for (int j = N * N; j >= 0; --j) {
                for (int k = S; k >= 0; --k) {
                    if (dp[j][k] != 0) {
                        // use
                        if (k + i <= S) {
                            (dp[j + 1][k + i] += dp[j][k]) %= MOD;
                        }
                    }
                }
            }
        }

        print(dp[N * N][S]);
    }
    return 0;
}


Measured memory_bytes: 4172
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define eps 1e-5
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin>>n;
	ll t[n],a[n];
	ll ch=0,aoki=0;
	rep(i,n)cin>>t[i]>>a[i];
	loop(i,1,n){
		if(t[i]<t[i-1] || a[i]<a[i-1]){
			ll p=max(t[i-1]/t[i]+((t[i-1]%t[i])?1:0),a[i-1]/a[i]+((a[i-1]%a[i])?1:0));
			t[i]*=p;
			a[i]*=p;
		}
	}
	cout<<t[n-1]+a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256