akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
    private static Scanner scanner = new Scanner( System.in );
    public static void main(String args[]) {
       
        int a =  scanner.nextInt();
        int b =  scanner.nextInt();
        int  product = a*b;
        if(product % 2 == 0){System.out.print("Even");}
        else{System.out.print("Odd");}
    }
}


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

int main() {
    int N, M;
    std::cin >> N >> M;

    int p;
    std::string S;
    bool AC[N + 1];
    int WA[N + 1];
    for (int i = 0; i < N + 1; ++i) {
        AC[i] = false;
        WA[i] = 0;
    }

    int ac_count = 0, wa_count = 0;
    for (int i = 0; i < M; ++i) {
        std::cin >> p >> S;
        if (AC[p]) {
            continue;
        }

        if (S == "AC") {
            ac_count++;        
            AC[p] = true;
            wa_count += WA[p];
        } else {
            WA[p] += 1;
        }
    }

    std::printf("%d %d\n", ac_count, wa_count);

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> l(2*n);
  for(int i = 0; i < 2 * n; i++){
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  int out = 0;
  for(int i = 0; i < n; i++){
    out += l.at(2 * i);
  }
  cout << out;
}

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

using namespace std;

typedef long long int ll;
const int mod = 1e9 +7;

int n;
ll dp[105][4][4][4];

bool valid(int a, int b, int c, int d) {

    if(a == 0 && b == 1 && c == 2) return false; //AGCX
    if(a == 1 && b == 0 && c == 2) return false; //GACX
    if(a == 0 && b == 2 && c == 1) return false; //ACGX
    if(a == 0 && b == 1 && d == 2) return false; //AGXC
    
    if(b == 0 && c == 1 && d == 2) return false; //XAGC
    if(b == 1 && c == 0 && d == 2) return false; //XGAC
    if(b == 0 && c == 2 && d == 1) return false; //XACG
    if(a == 0 && c == 1 && d == 2) return false; //AXCG -> was missing this one
    
    return true;
}

ll dag(int ind, int a, int b, int c) {
    
    if(dp[ind][a][b][c] != -1) return dp[ind][a][b][c];
    
    if(ind == n) {
        return 1;
    }
    
    ll ans = 0;
    
    for(int i = 0; i < 4; ++i) {
        if(valid(a,b,c,i)) {
            ans += dag(ind+1,b,c,i);
            ans %= mod;
        }
    }
    
    dp[ind][a][b][c] = ans;
    return ans;
}

int main() {
    
    cin >> n;
    
    for(int i = 0; i <= 100; ++i) {
        for(int q = 0; q < 4; ++q) {
            for(int w = 0; w < 4; ++w) {
                for(int e = 0; e < 4; ++e) {
                    dp[i][q][w][e] = -1;
                }
            }
        }
    }
    
    ll ans = dag(0,3,3,3);
    ans %= mod;
    
    cout << ans << endl;
    
    return 0;
}


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

#include<iostream>
#include<string>
#include<vector>
#include<algorithm> 
#include<functional> 
#include<cassert>
#include<numeric>
// std::accumulate(vec.begin(),vec.end(),0) sum of element
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<queue>


using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef vector<int> vi;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(c) c.begin(),c.end()
#define show(x) cout << #x << " = " << x << endl

#define fi first
#define se second
#define pb push_back
#define mk make_pair


template <class X>
void unique_vector(std::vector<X> &t);
template <class X>
void print_vector(const std::vector<X> &t);

int main(){
  string s;
  cin >> s;
  string s1(s,0,4);
  s1 = s1 +' ';
  string s2(s,4,s.size()-1);

  cout << s1 << s2 << endl;
}


template <class X>
void unique_vector(std::vector<X> &t)
{
  std::sort(t.begin(), t.end());
  t.erase( std::unique(t.begin(), t.end()), t.end() );
}

template <class X>
void print_vector(const std::vector<X> &t){
  for(auto itr=t.begin(); itr != t.end(); itr++){
    std::cout << *itr;
    if(itr != t.end()-1) std::cout << ' ';
  }
  std::cout << std::endl;
}


Measured memory_bytes: 760
#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>;

const int MX = 1000005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime 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;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;}
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    Sieve sieve(1e6);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    map<int,int> mp;
    rep(i,n) {
        auto f = sieve.factor(a[i]);
        for (auto p : f) {
            mp[p.first] = max(mp[p.first], p.second);
        }
    }

    mint lcm = 1;
    for (auto p : mp) {
        rep(i,p.second) {
            lcm *= p.first;
        }
    }

    mint ans;
    rep(i,n) {
        mint b = lcm/a[i];
        ans += b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7640
#include<iostream>
using namespace std;
long long mod=1e9+7; 
long long num[1000005];
long long  modl(long long a, long long b, long long c)//快速幂取余a^b%c
{
    long long res,t;
    res = 1 % c;
    t = a % c;
    while (b)
    {
        if(b&1)
        res=res*t%c;
        t=t*t%c;
        b>>=1;
    }
    return res;
} 
int main()
{
	long long n,a,cnt,flag;
	cin>>n;
	flag=cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		num[a]++;
		if(num[a]==2)
		cnt++;
		if(num[a]>2||num[0]>1)
		flag=1;
	}
	if(flag==1)
	{
		cout<<'0'<<endl;
		return 0;
	}
	else
	{
		cnt%=mod;
		cout<<modl(2,cnt,mod)%mod<<endl;
	} 
	return 0;
}

Measured memory_bytes: 1152
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    //println!("start");
    let a:Vec<i64>=read_vec();

    if (a[0]%3==0)||(a[1]%3==0)||((a[0]+a[1])%3==0){
        println!("Possible");
    }else{
        println!("Impossible");
    }
}



Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(100000)

ans=0


def dfs(v,n,visi):
    allv=True

    for i in visi:
        if not i:
            allv=False

    if allv:
        return 1

    ret=0

    for i in range(n):
        if G[v][i]==False:
            continue
        if visi[i]:
            continue
        visi[i]=True
        ret+=dfs(i,n,visi)
        visi[i]=False

    return ret

n,m=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(m)]
G=[[False for i in range(8)]for i in range(8)]

for a,b in ab:
    G[a-1][b-1]=G[b-1][a-1]=True

visi=[False for i in range(n)]

visi[0]=True

print(dfs(0,n,visi))

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

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

struct Data {
  int r, l, k;
};
int main() {
  string S;
  cin >> S;
  int n = S.length();
  vector<Data> d(n);
  for (int i = 0; i < n; i++) {
    if (S[i] == 'R') {
      d.push_back(Data());
      d[i].k = 0;
    } else {
      d[i].k = 1;
    }
  }
  d[0].r = 0;
  for (int i = 1; i < n; i++) {
    if (S[i] == 'R') {
      d[i].r = i;
    } else {
      d[i].r = d[i - 1].r;
    }
  }
  d[n - 1].l = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    if (S[i] == 'L') {
      d[i].l = i;
    } else {
      d[i].l = d[i + 1].l;
    }
  }
  int cnt[n]{};
  for (int i = 0; i < n; i++) {
    int g;
    if (d[i].k == 0) {
      g = d[i].l - i;
      if (g % 2 == 0) {
        cnt[d[i].l]++;
      } else {
        cnt[d[i].l - 1]++;
      }
    } else {
      g = i - d[i].r;
      if (g % 2 == 0) {
        cnt[d[i].r]++;
      } else {
        cnt[d[i].r + 1]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      cout << cnt[i] << "\n";
    } else {
      cout << cnt[i] << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(){
	int r, c, list[101][101];
	int i = 0, j = 0;
	scanf("%d %d", &r, &c);

	for(i = 0;i < r;i++){
		for(j = 0;j < c;j++){
		scanf("%d", &list[i][j]);
		}
	}

	for(i = 0;i < r + 1;i++){
		for(j = 0;j < c + 1;j++){
		    if(j != 0) printf(" ");
			if(j == 0) list[i][c] = 0;
			if(j != c)list[i][c] += list[i][j];
			if(i == 0) list[r][j] = 0;
			if(i != r)list[r][j] +=  list[i][j];
			printf("%d", list[i][j]);
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2124
A,B,C,D,E,F=map(int,input().split())
dp1=[0]*31
dp1[0]=1
m=0
for i in range(1,31):
    if i-A>=0:
        dp1[i]=max(dp1[i],dp1[i-A])
        m=(i)*E
    if i-B>=0:
        dp1[i]=max(dp1[i],dp1[i-B])
        m=(i)*E
dp2=[0]*(1+m)
dp2[0]=1
for i in range(m+1):
    if i-C>=0:
        dp2[i]=max(dp2[i],dp2[i-C])
    if i-D>=0:
        dp2[i]=max(dp2[i],dp2[i-D])
ans=0
w=0
s=0
for i in range(1,31):
    if dp1[i]==0:
        continue
    for j in range(1+m):
        if dp2[j]==0:
            continue
        if j<=i*E and i*100+j<=F:
            if ans<100*j/(i*100+j):
                ans=100*j/(i*100+j)
                w=100*i
                s=j
if s==0:
    print(min(A,B)*100,0)
    quit()
print(w+s,s)


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

typedef long long ll;

const int MAXN = 100 * 1000 + 10;

int main()
{
    int x,y;
    cin>>x>>y;
    if(x<=0 && y>=0){
        return cout<<"Zero",0;
    }
    if((x>0 && y>0) || (x==y)){
        return cout<<"Positive",0;
    }
    if(x<0 && y<0){
        if(((-1*x)-(-1*y))%2==0){
            return cout<<"Negative",0;
        }
        else{
            return cout<<"Positive",0;
        }
    }
}

Measured memory_bytes: 256
/*
    i have no idea
*/

#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

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

    int l[n], r[n];
    for (int i = 0; i < n; i++){
        if (i) l[i] = __gcd(a[i], l[i-1]);
        else l[i] = a[i];
    }

    for (int i = n-1; i >= 0; --i){
        if (i < n-1) r[i] = __gcd(a[i], r[i+1]);
        else r[i] = a[i];
    }
    int ans = max(r[1], l[n-2]);
    for (int i = 1; i < n-1; i++){
        ans = max(ans, __gcd(l[i-1], r[i+1]));
    }

    cout << ans;
}


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

int main() {
	int s1s2s3;

	cin >> s1s2s3;

	if (s1s2s3 == 111)
		cout << "3" << endl;

	if (s1s2s3<=110)
		cout << s1s2s3 % 3 << endl;

}


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

int main() {
  int A, B, C;
  vector<int> num(3);
  cin >> num.at(0) >> num.at(1) >> num.at(2);
  sort(num.begin(), num.end());
  if(num.at(0) == 5 & num.at(1) == 5 & num.at(2) == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	string s; cin >> s;
	bool f = s[2] == s[3] and s[4] == s[5];
	Yn(f);	
}

Measured memory_bytes: 256
#include<stdio.h>

#define mod 1000000007

int main(){
		int n,i,j;
		char s[100001];
		scanf("%s",s);
		for(i=0;s[i]!=0;i++);
		n=i;
		long long dp[100001][4];
		dp[n][3]=1;
		dp[n][2]=0;
		dp[n][1]=0;
		dp[n][0]=0;
		for(i=n-1;i>=0;i--){
				char t=s[i];
				int m=(t=='?'?3:1);
				for(j=0;j<4;j++)dp[i][j]=m*dp[i+1][j];
				if(t=='A'||t=='?')dp[i][0]+=dp[i+1][1];
				if(t=='B'||t=='?')dp[i][1]+=dp[i+1][2];
				if(t=='C'||t=='?')dp[i][2]+=dp[i+1][3];
				for(j=0;j<4;j++)dp[i][j]%=mod;
		}
		printf("%lld\n",dp[0][0]);
		return 0;
}


Measured memory_bytes: 3328
/*	
*  Sachin Mittal
*/
#include<bits/stdc++.h>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,j,n) for(int i=j;i<n;i++)
#define F first
#define S second
#define lb lower_bound
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define sz(s) (int)(s.size())
#define debug(x) cout << #x << " = " << x << '\n';
using namespace std;

int fast_power(int base,int power,int modulo)
{
	int result=1;
	while(power)
	{
		if(power%2)
		result=(result*base)%modulo;
		base=(base*base)%modulo;
		power/=2;
	}
	return result;
}

void solve()
{
	int n,k;cin>>n>>k;
	vector<int> v(k+1,0);
	for(int i=1;i<=k;i++)
	{
		int tms=k/i;
		v[i]=fast_power(tms,n,mod);
	}	
	int ans=0;
	for(int i=k;i>=1;i--)
	{
		int sm=0;
		for(int j=2*i;j<=k;j+=i)
			sm=(sm+v[j])%mod;
		int add=(v[i]-sm+mod)%mod;
		v[i]=add;
		add=(add*i)%mod;
		ans=(ans+add)%mod;
	}
	cout<<ans;
	
}

int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
	solve();
}
}

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

using namespace std;

int main() {
    string red, blue, ab;
    int r = 0;
    int b = 0; 
    cin >> red >> blue;
    cin >> r >> b;
    cin >> ab;

    if (ab == blue) {
        cout << r << '\t' << b-1;
    }
    else {
        cout << r-1 << '\t'<< b << endl;
    }




    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,c,d,e;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(c>=min(a,b)){
	printf("%d\n",min(a,b)+min(d,e)-50);
	}else{printf("%d\n",c+min(d,e)-50);}
	return 0;
}


Measured memory_bytes: 3148
H, W, K = gets.split.map(&:to_i)
C = H.times.map { gets.chomp.split("") }

ans = 0
hs = 0.upto(H-1).to_a
ws = 0.upto(W-1).to_a
0.upto(H-1) do |i|
  hs.combination(i).each do |h_comb|
    0.upto(W-1) do |j|
      ws.combination(j).each do |w_comb|
        c = C.map(&:dup)
        h_comb.each do |h|
          c[h] = c[h].map { nil }
        end
        w_comb.each do |w|
          H.times do |ii|
            c[ii][w] = nil
          end
        end
        tmp = 0
        H.times do |i|
          W.times do |j|
            tmp += 1 if c[i][j] == "#"
          end
        end
        ans += 1 if K == tmp
      end
    end
  end
end

puts(ans)


Measured memory_bytes: 14384
#ABC159-E Dviding Chocolate
"""
(ループで変数kを使いたい為、入力kはgとして受け取っているので注意)
process1:
まず、Hの制約が10以下であることから、どこで分割するかをbit全探索する。(最大2**9回)
次にresを空のリストで用意し、分割数だけ累積和で圧縮した横方向のチョコレートを入れる。
分割されたそれぞれのチョコレートについて、累積和をとったので、例えば
1101
0101　のように分割されたチョコレートは、
↓
1202　というように1行に圧縮して表される。

process2-#1:
次に、それぞれの部分チョコレートについて、それぞれの一列が条件を満たしているかどうかを調べる
必要があるが、これは後回しにする。

process3:
実際に縦方向に最低何分割する必要があるかをサーチする。この時、各部分チョコレートについて
回してしまうと、最適な分割数を求めることができない。
横方向にループを回して、すべての部分チョコレートについて並行にサーチし、初めてg > count
(countは1の数)となってしまった列で分割数を+1し、縦方向の分割数(これはblstの各要素の1の数
から求める。)との合計をとってansを更新する。

process2-#2:
さてここで、process3の分割の条件は"各部分チョコレートについて、初めて条件を満たさなくなった時
に分割を増やす"であったが、既に1列がg >= countを満たさない場合、どのように縦方向で分割しても
条件を満たさないので、これは横方向の分割の時点で弾かなければならない。
例；
3 4 1
1101
0001
0001
横方向に必ず3分割しないと条件を満たさないので、他のものを弾く。
"""
import sys
readline = sys.stdin.buffer.readline

h,w,g = map(int,readline().split())

maze = []
for i in range(h):
    s = readline().rstrip().decode('utf-8')
    maze.append(s)

#ビット全探索
def bit_list(dig): #引数に何桁かを入れる
    lst = []
    for i in range(2**dig):
        lst.append(list(format(i,"b").zfill(dig)))
    return lst
#帰ってくるのは[[0,0,1],[0,1,0],[0,1,1],[1,0,0]...[1,1,1]]のようなリスト

blst = bit_list(h-1) #どこで分割するかが入っているリスト
ans = 10**9

for i in range(len(blst)):
    res = []
    lst1 = [0]*w
    #process1
    for k in range(w): #分割数はn-1なので、最初の1行目は手動で
                lst1[k] += 1 if maze[0][k] == "1" else 0
    
    for index,j in enumerate(blst[i],1):
        if j== "0": #分割しない
            for k in range(w):
                lst1[k] += 1 if maze[index][k] == "1" else 0
        else:
            res.append(lst1)
            lst1 = [0]*w
            for k in range(w):
                lst1[k] += 1 if maze[index][k] == "1" else 0
    
    res.append(lst1)

    #process2
    #横分割しなかった部分について、縦分割することで必ず条件を満たせる必要がある。
    flag = 0
    for j in res:
        if any(k > g for k in j):
            flag = 1
            break
    if flag:
        continue

    #process3
    w_cut = 0
    count = [0]*len(res)
    for j in range(w):
        now_count = [0]*len(res)
        for index,k in enumerate(res):
            count[index] += k[j]
            now_count[index] += k[j]
        if any(l > g for l in count):
            count = now_count
            w_cut += 1


    ans = min(ans,blst[i].count("1")+w_cut)

print(ans)

Measured memory_bytes: 53340
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,ans,s;
string st;
int main()
{
	cin>>st;
	n=st.length()-1;
	for (i=0;i<(1<<(n));i++)
	{
		s=0;
		for (j=0;j<=n;j++)
		{
			s=s*10+st[j]-'0';
			if ((1<<j)&i)
			{
				ans+=s;
				s=0;
			}
		}
		ans+=s;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, l: [usize; n]};
    let l: Vec<usize> = l;

    let mut count = 0;

    for i in 0..n {
        for j in i..n {
            for k in j..n {
                let mut v = Vec::new();

                v.push(l[i]);
                v.push(l[j]);
                v.push(l[k]);

                v.dedup();
                v.sort();

                if v.len() == 3 && v[0] != v[1] && v[1] != v[2] {
                    if v[2] < (v[0] + v[1]) {
                        count += 1;
                    }
                }
            }
        }
    }

    println!("{}", count)
}


Measured memory_bytes: 2280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

class Solution
{
    static void Main(string[] args)
    {
        int[] nab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Console.WriteLine((nab[2] - nab[1]) % 2 == 0 ? "Alice" : "Borys");
    }
}


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

int main(){
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    int x[n], y[m];
    for(int i = 0; i < n; i++)  cin >> x[i];
    for(int i = 0; i < m; i++)  cin >> y[i];
    sort(x, x+n);
    sort(y, y+m);

    bool war = true;
    for(int i = X+1; i <= Y; i++){
        if(x[n-1] < i && i <= y[0]) war = false;
    }

    if(war) cout << "War" << endl;
    else    cout << "No War" << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func reverse(S string) string {
	s := []byte(S)
	for i := 0; i < len(s)/2; i++ {
		s[i], s[len(s)-1-i] = s[len(s)-1-i], s[i]
	}
	return string(s)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()

	s = reverse(s)
	d0 := reverse("dream")
	d1 := reverse("dreamer")
	d2 := reverse("erase")
	d3 := reverse("eraser")

	pos := 0
	// out(s)
	for pos != len(s) {
		if strings.HasPrefix(s[pos:], d0) {
			// out(d0)
			pos += len(d0)
		} else if strings.HasPrefix(s[pos:], d1) {
			// out(d1)
			pos += len(d1)
		} else if strings.HasPrefix(s[pos:], d2) {
			// out(d2)
			pos += len(d2)
		} else if strings.HasPrefix(s[pos:], d3) {
			// out(d3)
			pos += len(d3)
		} else {
			out("NO")
			return
		}
	}
	out("YES")
}


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

	

int main(){
	int n;
	cin >> n;
	priority_queue<pair<int, int>> que;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		que.emplace(b,a);
	}

	string ans = "Yes";
	int remain=INF;
	while(!que.empty()){
		int a,b;
		a=que.top().second; b=que.top().first; que.pop();
		if(remain < a || b < a){ ans = "No"; break;}
		remain = min(remain-a, b-a);
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
N=int(input())
binaly=[int(s) for s in input().split()]

boxes=[0 for _ in range(N)]
ans=set()

for i in range(N-1,-1,-1):
  if sum(boxes[i::i+1])%2!=binaly[i]:
    boxes[i]=1
    ans.add(i+1)
print(len(ans))
print(*ans)


Measured memory_bytes: 105360
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int time;
}P;

P Q[LEN+1];
int head=0, tail=0;

void enqueue(P x){/* Q[tail] に x を代入し、tail を１つ増やします。 */
  int next = (tail+1)%LEN;
    
  if (next == head) {
    /* キューがいっぱいの場合のエラー処理 */
    printf("Queue overflow!\n");
    exit (2);
  }
  
  Q[tail] = x;
  tail = next;
}

P dequeue(){/* Q[head] の値を返し、head を１つ増やします。  */
  P t;
    
  if (head == tail) {/* キューが空の場合のエラー処理 */
    t.time = -1;
    return t;
  }
  
  t = Q[head];
  head = (head+1)%LEN;
  return t;
}


int main(){
  
  int total = 0;/* かかった総時間 */
  int i, n, q;/* ループ変数、クオンタム */
  P u;/* メインで使う構造体の宣言 */
  scanf("%d %d", &n, &q);/* プロセス数を表す整数 n とクオンタムを表す整数 q */
/* 続く n 行で、各プロセスの情報が順番に与えられます */                    
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
    enqueue(Q[i]);/*キューに追加 */ 
  }

/* 以下実行部分 */
  while(1){
    u = dequeue();
    if(u.time == -1)break;
    if(u.time > q){/* 時間内に終了しない場合時間を減らし末尾に追加 */
      u.time -= q;
      total += q;
      enqueue(u);
    }
    else if(u.time <=  q){/* データ名とかかった総時間の表示 */
      total += u.time;
      printf("%s %d\n",u.name,total);
    }
  }
  
  return 0;
}



Measured memory_bytes: 11860
s = input()

ans = 'Yes'
so = [s[i] for i in range(0,len(s),2)]
se = [s[i] for i in range(1,len(s),2)]

for i in so:
    if i == 'L':
        ans = 'No'

for i in se:
    if i == 'R':
        ans = 'No'
print(ans)

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

int main(){
  int x, y;
  bool YNflag = false;
  cin >> x >> y;
  for(int i = 0; i < x + 1; i++){
    for(int j = 0; j < x + 1 - i; j++){
      if(y == 2 * i + 4 * j && x == i + j){
        YNflag = true;
        break;
      }
    }
  }
  YNflag ? cout << "Yes" : cout << "No";
  cout << endl;
}


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

int main(){
  ll h,w,k,max,tmp,ans,i,j,m,l,b,c,x,y;
  ans=0;
  max=0;
  string s;
  cin >> h >> w >> k;
  ll a[h+1][w+1]={0};
  for(i=0;i<=h;i++){
    for(j=0;j<=w;j++){
      a[i][j]=0;
    }
  }
  for(i=1;i<=h;i++){
    cin >> s;
    for(j=0;j<w;j++){
      if(s.substr(j,1)=="."){
        a[i][j+1]=0;
      }
      else if(s.substr(j,1)=="#"){
        a[i][j+1]=1;
        a[0][j+1]+=1;
        a[i][0]+=1;
        max+=1;
      }
    }
  }
  b=pow(2,h);
  c=pow(2,w);
  for(i=0;i<b;i++){
    for(j=0;j<c;j++){
      tmp=max;
      for(m=1;m<=h;m++){
        x=i/pow(2,m-1);
        if(x%2==1){
          tmp-=a[m][0];
        }
      }
      for(l=1;l<=w;l++){
        y=j/pow(2,l-1);
         if(y%2==1){
          tmp-=a[0][l];
           for(m=1;m<=h;m++){
             x=i/pow(2,m-1);
             if(x%2==1){
               tmp+=a[m][l];
             }
           }
        } 
      }
      if(tmp==k){
        ans+=1;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 4064
import Data.Int
import Data.Bits

solve :: Int64 -> Int64 -> Int -> Int64
solve a b i
  | i == 0 = (a`div`2 - b`div`2 + b`mod`2) `mod` 2
  | otherwise = shiftL (((if testBit a i then a-l else 0) + (if testBit b i then r-b-1 else 0)) `mod` 2) i
  where
    l = a .&. (complement $ (bit i) - 1)
    r = b .&. (complement $ (bit i) - 1) + bit i


main :: IO ()
main = do
  [a,b] <- map read . words <$> getLine :: IO [Int64]

  print $ sum $ map (solve a b) [0..64]


Measured memory_bytes: 508
#include<stdio.h>

int main(void){
	int i;
	char str[21]={};
	scanf("%s",str);
	for(i=21;i>-1;i--){
	if(str[i] > 32 && str[i] != 127 && str[i] != 60){
		printf("%c",str[i]);
	}
	}
	printf("\n");
return 0;
}

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

using namespace std;

using ull = unsigned long long;

ull solve(string N, ull K) {
    // vector<vector<vector<ull>>> dp(N.length() + 1, vector<vector<ull>>(2, vector<ull>(K + 1, 0)));
    // memset(dp, 0ULL, sizeof(dp));
    vector<vector<vector<ull>>> dp(N.length() + 1);
    // vector<vector<vector<ull>>> dp(8);
    for (ull i = 0; i < dp.size(); i++) {
        dp[i].resize(2, vector<ull>(K + 2, 0));
    }

    dp[0][0][0] = 1;

    int D;
    for (int i = 0; i < N.length(); i++) {
        D = N[i] - '0';
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k <= K; k++) {
                for (int d = 0; d <= (j ? 9 : D); d++) {
                    dp[i + 1][j || (d < D)][k + (d == 0 ? 0 : 1)] += dp[i][j][k];
                }
            }
        }
    }

    ull ans = dp[N.length()][0][K] + dp[N.length()][1][K];
    return ans;
}


int main() {
    string N;
    ull K;
    cin >> N >> K;
    cout << solve(N, K) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	int ai = a[n - 1];
	int aj;
	rep(i, n) {
		if (!i)aj = a[i];
		else {
			if (abs((double)ai / 2 - (double)a[i]) < abs((double)ai / 2 - (double)aj))aj = a[i];
		}
	}
	cout << ai << " " << aj;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll H, W, ans = mod, S;
	ll s1, s2, s3, row;
	cin >> H >> W;
	row = (H + 1) / 3;
	s1 = row * W;
	s2 = (H - row) * (W / 2);
	s3 = (H - row) * (W - W / 2);
	S = max({ s1,s2,s3 }) - min({ s1,s2,s3 });
	ans = min(ans, S);

	row = (W + 1) / 3;
	s1 = row * H;
	s2 = (W - row) * (H / 2);
	s3 = (W - row) * (H - H / 2);
	S = max({ s1,s2,s3 }) - min({ s1,s2,s3 });
	ans = min(ans, S);

	row = (H + 1) / 3;
	s1 = row * W;
	s2 = ((H - row) / 2) * W;
	s3 = ((H - row) - ((H - row) / 2)) * W;
	S = max({ s1,s2,s3 }) - min({ s1,s2,s3 });
	ans = min(S, ans);

	row = (W + 1) / 3;
	s1 = row * H;
	s2 = ((W - row) / 2) * H;
	s3 = ((W - row) - ((W - row) / 2)) * H;
	S = max({ s1,s2,s3 }) - min({ s1,s2,s3 });
	ans = min(S, ans);

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct SegmentTree {
private:
    int n;
    vector<T> node;
    T def;
    function<T(T,T)> out;
    
public:
    SegmentTree() {}
    SegmentTree(const vector<T> &v, T _def, function<T(T,T)> _out) {
        int vl = (int)v.size();
        n = 1;
        while(n < vl) n *= 2;
        def = _def; out = _out;
        node = vector<T>(2 * n - 1, def);
        for(int i = 0; i < vl; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    void update(int idx, T val) {
        idx += (n - 1);
        node[idx] = val;
        while(idx > 0) {
            idx = (idx - 1) / 2;
            node[idx] = out(node[idx * 2 + 1], node[idx * 2 + 2]);
        }
    }
    
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if ((r <= a) || (b <= l)) return def;
        if ((a <= l) && (r <= b)) return node[k];
        return out(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll A, B, M;
    cin >> A >> B >> M;
    vector<ll> a(A), b(B);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    vector<map<ll, ll>> xy(A);
    rep(i, M) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        if (xy[x].count(y) == 0) {
            xy[x][y] = c;
        }
        else {
            xy[x][y] = max(xy[x][y], c);
        }
    }
    rep(i, A) {
        rep(j, sz(xy[i])) {
            
        }
    }
    vector<ll> sb(B);
    rep(i, B) sb[i] = b[i];
    sort(all(sb));
    ll minb = sb[0];
    SegmentTree<ll> st(b, inf, [](ll a, ll b){ return min(a, b); });
    ll ans = LONG_LONG_MAX;
    rep(i, A) {
        ll tmp = a[i] + minb;
        for(auto x : xy[i]) {
            ll idx = x.first;
            ll v = b[idx];
            st.update(idx, v - x.second);
        }
        ll mv = st.query(0, B);
        tmp = min(tmp, a[i] + mv);
        ans = min(ans, tmp);
        for(auto x : xy[i]) {
            ll idx = x.first;
            ll v = b[idx];
            st.update(idx, v);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15616
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;
int x[10];

int main(void) {
    rep(i, 1, 6) cin >> x[i];

    rep(i, 1, 6) {
        if (x[i]==0) {
            printf("%d\n", i);
            return 0;
        }
    }


    return 0;
}



Measured memory_bytes: 3764
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int inf = 1000000000;

int n;
vector<string> a;

void input() {
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
}

// 盤面がすべて白かどうかを判定
bool all_white() {
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			if (a[i][j] == '#')
				return false;
	return true;
}

// まず上からx行目をall blackにするとき、全体での回数
int solve(int x) {
	int res = 0;
	// 上からx行目をall blackにする
	bool b_exist = false;
	for (int j = 0; j < n; ++j) {
		if (a[j][x] == '#') {
			b_exist = true;
			break;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (a[x][i] == '#') continue;
		++res;
	}
	if (res && (!b_exist)) ++res;
	// 左の列から順にall blackにする
	for (int j = 0; j < n; ++j) {
		bool all_black = true;
		for (int i = 0; i < n; ++i) {
			if (a[i][j] == '.') {
				all_black = false;
				break;
			}
		}
		if (!all_black) ++res;
	}
	return res;
}

int main() {
	input();
	if (all_white()) cout << -1 << endl;
	else {
		int ans = inf;
		for (int x = 0; x < n; ++x)
			ans = min(ans, solve(x));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    string s,t; cin >> s >> t;
    int a,b; cin >> a >> b;
    string u; cin >> u;
    if(u==s){
        cout << a-1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }
}

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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long ans1,ans2,ans3,ans4;
  ans1 = a * c,ans2 = a * d,ans3 = b * c,ans4 = b * d;
  //cout << ans1 << endl;
  cout << max({ans1,ans2,ans3,ans4}) << endl;
}

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

using namespace std;
int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> s(m);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int sn;
			cin >> sn;
			s[i].push_back(sn);
		}
	}
	int p[m];
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	
	bool sw[n];
	for (int i = 0; i < n; i++) {
		sw[i] = false;
	}
	int ans = 0;
	while (true) {
//		for (int i = 0; i < n; i++) {
//			cout << "switch" << i << ":" << sw[i] << " ";
//		}
//		cout << endl;
		
		bool breakFlag = false;
		for (int i = 0; i < m && !breakFlag; i++) {
			int swCount = 0;
			for (int j = 0; j < s[i].size(); j++) {
				if (sw[s[i][j]-1]) {
					swCount += 1;
				}
			}
			if (swCount % 2 != p[i]) {
				breakFlag = true;
			}
		}
		if (!breakFlag) {
			ans += 1;
//			cout << "このスイッチパターンでは全ての電球が点灯しています" << endl;
		}
		
		int k = 0;
		while (k < n) {
			if (!sw[k]) {
				sw[k] = true;
				break;
			} else {
				sw[k++] = false;
			}
		}
		
		if (k >= n) {
			break;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a,b,c,d = map(int,input().split())
    if a+b>c+d:
        print('Left')
    elif a+b<c+d:
        print('Right')
    else:
        print('Balanced')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    map<lint, lint> cnt;
    lint ret = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
        ret += a[i];
    }
    lint q;
    cin >> q;
    vector<lint> b(q), c(q);
    for (int i = 0; i < q; ++i) {
        cin >> b[i] >> c[i];
    }
    for (int i = 0; i < q; ++i) {
        ret -= b[i] * cnt[b[i]];
        ret += c[i] * cnt[b[i]];
        cnt[c[i]] += cnt[b[i]];
        cnt[b[i]] = 0;
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 11680
import sys
from itertools import islice, repeat


def _resolve(costs, k):
    sum_ = sum(costs)
    v = 0
    if k >= len(costs):
        if sum_ > 0:
            x = k // len(costs) - 1
            v = x * sum_
            k -= x * len(costs)
        else:
            k = len(costs)

    points = [v] * (len(costs) * (k + 1))
    for i in range(k):
        for n in range(len(costs)):
            points[(i + 1) * len(costs) + n] = points[i * len(costs) + n] + costs[(i + n) % len(costs)]
    
    ans = max(points)
    if ans == 0:
        y = max(costs)
        if y < 0:
            ans = y
    return ans


def resolve(in_):
    N, K = map(int, next(in_).split())
    P = [0] + list(map(int, next(in_).split()))
    C = [0] + list(map(int, next(in_).split()))

    graphs = []
    p = set(P[1:])
    while p:
        index = p.pop()
        graph = [C[index]]
        index = P[index]
        while index in p:
            graph.append(C[index])
            p.remove(index)
            index = P[index]
        graphs.append(graph)

    ans = max(map(_resolve, graphs, repeat(K)))
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 457392
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()
ans = sum(s)
i = 0
if ans%10 == 0:
    for c in s:
        if c%10 != 0:
            ans-=c
            break

if ans%10 == 0:
    ans = 0    
print(ans)


Measured memory_bytes: 3060
// 期待値とかしらねぇけどサンプル2を眺めて分解してそれをもとにサンプル3を再構築したら見えてきた
package main

import "fmt"

var n, m int

func main() {
	fmt.Scan(&n, &m)
	b := 1
	for i := 0; i < m; i++ {
		b *= 2
	}
	fmt.Println(((n-m)*100 + 1900*m) * b)
}


Measured memory_bytes: 512
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1010;
char s[SIZE][SIZE];
int dp[SIZE][SIZE];
int main(){
    int n,m;
    R(n,m);
    FOR(i,1,n)RS(s[i]+1);
    FOR(i,1,n)FOR(j,1,m){
        if(i==1&&j==1){
            dp[i][j]=(s[i][j]=='#');
        }
        else{
            dp[i][j]=1e9;
            if(i>1)dp[i][j]=min(dp[i][j],dp[i-1][j]+(s[i][j]=='#'&&s[i-1][j]=='.'));
            if(j>1)dp[i][j]=min(dp[i][j],dp[i][j-1]+(s[i][j]=='#'&&s[i][j-1]=='.'));
        }
    }
    W(dp[n][m]);
    return 0;
}


Measured memory_bytes: 3196
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val (n,k) = readLine()!!.split(" ").map{it.toInt()}
    val p = readLine()!!.split(" ").map{it.toDouble()}
    var sum = 0.0
    var ans = 0.0
    for(i in 0 until n){
        sum += p[i] * (p[i] + 1) / 2 / p[i]
        if(i >= k) sum -= p[i - k] * (p[i - k] + 1) / 2 / p[i - k]
        if(i + 1 >= k){
            ans = Math.max(ans, sum)
        }
    }
    println("%.20f".format(ans))
}

Measured memory_bytes: 81088
// A 
#include<bits/stdc++.h>
#define pb push_back 
#define mp make_pair
using namespace std;

const int maxn=1e5+7;
typedef long long ll;

int n,m;
ll a[maxn];

vector<ll>ans;

int main()
{
/* 
#ifndef LOCAL
	freopen("","r",stdin);
	freopen("","w",stdout);
#endif*/

	int i,j,k,T;
	scanf("%d",&n);
	
	for(i=1;i<=n;++i)
	  scanf("%lld",&a[i]);
	
	sort(a+1,a+n+1);
	
	for(i=n;i>1;--i)
	{
		if(a[i]==a[i-1])
		{
			if(ans.size()<=1)
			{
				ans.pb(a[i]);
				i--;
			}
		}
	}
	
	ll b=0;
	
	if(ans.size()>1) b=ans[0]*ans[1];
	
	printf("%lld\n",b);
	
	return 0;
}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define debugVector(v) for(int i = 0; it < v.size(); i++) cout << v[i] << " "; cout << endl;
#define debugArray(arr, n) for(int i=0; i<n; i++) cout << arr[i] << " "; cout << endl;
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	int a;
	cin >> a;
	int ans = a + (a*a) + (a*a*a);
	cout << ans << endl;
}

Measured memory_bytes: 3648
def args():
    N = int(input())
    ABC = []
    for _ in range(N):
        ABC.append(tuple(map(int, input().split())))

    # print(N)
    # print(ABC)

    return N, ABC


def solve(N, ABC):
    x, y = N + 1, 3
    DP = [[0 for _ in range(y)] for _ in range(x)]

    for i in range(N):
        for a in range(3):
            if a == 0:
                DP[i + 1][1] = max(DP[i + 1][1], DP[i][a] + ABC[i][1])
                DP[i + 1][2] = max(DP[i + 1][2], DP[i][a] + ABC[i][2])
            elif a == 1:
                DP[i + 1][0] = max(DP[i + 1][0], DP[i][a] + ABC[i][0])
                DP[i + 1][2] = max(DP[i + 1][2], DP[i][a] + ABC[i][2])
            elif a == 2:
                DP[i + 1][0] = max(DP[i + 1][0], DP[i][a] + ABC[i][0])
                DP[i + 1][1] = max(DP[i + 1][1], DP[i][a] + ABC[i][1])

    # print(DP)
    return max(DP[-1])


if __name__ == '__main__':
    res = solve(*args())
    print(res)


Measured memory_bytes: 76120
import sys

n,m = map(int, input().split())
AB = []
for _ in range(m):
    a,b = map(int, input().split())
    AB.append((a,b))

AB= sorted(AB, key=lambda x: x[1])

count = 0
pb = AB[0][1]
for a, b in AB[1:]:
    if a >= pb:
        count += 1
        pb = b
count += 1
print(count)


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

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

  if(K == 0){
    cout << static_cast<long long>(N) * N << endl;
    return 0;
  }

  long long ans = 0;
  for(int b = K + 1; b <= N; b++){
    // a = K, ..., b - 1,
    //     b + K, ..., 2b - 1, ..

    // nb - 1 <= N
    // n <= (N + 1) / b
    long long whole_size = (b - 1) - K + 1, whole_cnt = (N + 1) / b;
    ans += whole_size * whole_cnt;

    // nb + K <= N
    // n <= (N - K) / b
    long long partial_n = (N - K) / b;
    if(partial_n > whole_cnt - 1){
      ans += N - (partial_n * b + K) + 1;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
out = gcd(a[0], a[1])
for i in a[2:]:
    out = gcd(out, i)
print(out)

Measured memory_bytes: 14252
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		int c = (a * b) % 2;

		if(c == 1){
			System.out.println("Odd");
		}
		else{
			System.out.println("Even");
		}
	}

}

Measured memory_bytes: 21716
import sys
input = sys.stdin.readline

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

LIST=[0]*(10**6+1)

for a in A:
    LIST[a]+=1
ANS=0

for i in range(10**6+1):
    if LIST[i]==1:
        ANS+=1
    if LIST[i]!=0:
        for j in range(2*i,10**6+1,i):
            if LIST[j]!=0:
                LIST[j]+=1
print(ANS)
    


Measured memory_bytes: 106224
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    cin >> s;
    int i = 0;
    for(; s[i] != ','; i++) {
        cout << s[i];
    }
    cout << " ";
    i++;
    for(; s[i] != ','; i++)
        cout << s[i];
    cout << " ";
    i++;
    for(; i < (int)s.size(); i++)
        cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256