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

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,W;
int w[100010],v[100010];
int dp[111][100010];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N>>W;
    rep(i,0,N){
        cin>>w[i]>>v[i];
    }
    
    rep(i,0,111)rep(j,0,100010)dp[i][j]=INF;
    dp[0][0]=0;
    rep(i,0,N){
        rep(j,0,100010){
            chmin(dp[i+1][j],dp[i][j]);
            if(j<v[i])continue;
            chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
        }
    }
    int ans=0;
    rep(i,0,100010)if(dp[N][i]<=W)chmax(ans,i);
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 88320
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n;
    cin >> n;
    n++;
    int c = 0;
    for (int i = 40; i >= 0; --i) {
        if(n & (1LL << i)){
            c = i;
            n -= (1LL << i);
            break;
        }
    }
    vector<int> ans;
    for (int i = 1; i <= c; ++i) {
        ans.emplace_back(2*i);
    }
    for (int i = 40; i >= 0; --i) {
        if(n & (1LL << i)){
            ans.emplace_back(i*2+1);
            n -= (1LL << i);
        }
    }
    for (int i = 1; i <= 100; ++i) {
        ans.emplace_back(i);
    }
    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); ++i) {
        if(i) cout << " ";
        cout << ans[i];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
l = [list(map(int,input().split())) for i in range(2*K)]#一行ずつ格納
d = []
A = []
for i in range(K):
    d.append(l[2*i][0]) #Aiの長さ
    A.append(l[2*i +1]) #A[お菓子i][を持っているすぬけ君]

having = [0]*N #各すぬけ君の所持お菓子カウント
for i in range(K): #お菓子i
    for j in range(d[i]):
        having[A[i][j]-1] += 1
        
ans = 0
for i in range(N):
    if having[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9156
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
//#include <pair>
#include <map>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c * x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!= ) cerr << boolalpha << i; ris;
}
eni(== ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


const double pi = 3.141592653589793238462643383279502884197169399;
typedef long long ll;

void solve() {
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; ++i) {
		int element;
		cin >> element;
		sum += element;
	}
	if (n >= sum) {
		cout << (n - sum) << endl;
		return;
	}
	cout << -1 << endl;
}

	



int main() {
	//cout << fixed << setprecision(20) << endl;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("test.txt", "r", stdin);

	solve();
	return 0; 
}

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

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

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }

template<typename T = ll> struct UnionFind {
	vector<T> par;

	UnionFind( T n ) : par( n, -1 ) {}

	void init( T n ) { par.assign( n, -1 ); }
	T find( T x ) {
		if ( par[x] < 0 ) return ( x );
		else return ( par[x] = find( par[x] ) );
	}
	bool isSame( T x, T y ) {
		return ( find( x ) == find( y ) );
	}
	bool unite( T x, T y ) {
		x = find( x ); y = find( y );
		if ( x == y ) return ( false );
		if ( par[x] > par[y] ) swap( x, y );
		par[x] += par[y];
		par[y] = x;
		return ( true );
	}
	T size( T x ) { return ( -par[find( x )] ); }
};


int main()
{
	ll n, m; cin >> n >> m;
	UnionFind<ll> uf( n + 10 );

	rep( i, m )
	{
		ll a, b; cin >> a >> b;
		uf.unite( a, b );
	}

	ll ans = 0;
	rep( i, n )
	{
		chmax( ans, uf.size( i + 1 ) );
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 4344
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll7

VI G[114514];
int n;

void bfs(int s, int d[]){
    queue<P> que;
    fill(d,d+n,INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.front(); que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            int e = G[v][i];
            if(d[e]>d[v]+1){
                d[e] = d[v] + 1;
                que.push(P(d[e],e));
            }
        }
    }
}

void debug(int d[],int d2[]){
    REP(i,n) printf("%d ",d[i]);
    printf("\n");
    REP(i,n) printf("%d ",d2[i]);
    printf("\n");
}

signed main(){
    scanf("%d",&n);
    REP(i,n-1){
        int s,t;
        scanf("%d%d",&s,&t);
        s--; t--;
        G[s].pb(t);
        G[t].pb(s);
    }
    int d[114514];
    int d2[114514];
    bfs(0,d);
    bfs(n-1,d2);
    //debug(d,d2);
    int f=0,s=0;
    REP(i,n){
        if(d[i]>d2[i]) s++;
        else f++;
    }

    f>s ? puts("Fennec") : puts("Snuke");
    return 0;
}

Measured memory_bytes: 7108
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
int h[200010];
ll a[200010];
ll seg[1000010];


ll maxq(int t, int L, int R,int l, int r)
{
    if(l>=L && r<=R)
        return seg[t];
    if(L>r || l>R)
        return 0;

    int mid=(l+r)/2;
    ll m1=maxq(2*t,L,R,l,mid);
    ll m2=maxq(2*t+1,L,R,mid+1,r);
    return max(m1,m2);
}

void update(int t, int l, int r, int ind, ll vrednost)
{
    if(l==r)
    {
        seg[t]=vrednost;
        return;
    }
    int mid=(l+r)/2;
    if(ind <=mid) update(2*t,l,mid,ind,vrednost);
    else update(2*t+1,mid+1,r,ind,vrednost);
    seg[t]=max(seg[2*t],seg[2*t+1]);
}


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

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

    for(int i=0;i<n;i++)
    {
        ll v=a[i]+maxq(1,1,h[i]-1,1,n);
        update(1,1,n,h[i],v);
    }
    cout<<seg[1];

	return 0;
}


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




int main(){
   int n;
   cin>>n;
   int a[101010];
   rep(i,n){
	   int b;
	   cin>>b;
	   a[b-1]=i+1;
   }
   rep(i,n)cout<<a[i]<<" ";
   cout<<endl;
}



Measured memory_bytes: 1152
import sys
if sys.version_info[0]>=3: raw_input=input

def checkio(data):
	y=len(data)
	x=len(data[0])
	m=[[0]*x for i in range(y)]
	for j in range(y):
		r=0
		for i in range(x):
			#if data[j][i]=='.': r+=1
			if data[j][i]==1: r+=1
			else: r=0
			m[j][i]=r
	r=0
	for i in range(x):
		for j in range(y):
			M=9999999
			for k in range(j,y):
				M=min(M,m[k][i])
				r=max(r,M*(k-j+1))
	return r

if __name__=='__main__':
	n=int(raw_input())
	try:
		for _i in range(n):
			data=[[int(e) for e in raw_input().split()] for i in range(5)]
			print(checkio(data))
			raw_input()
	except EOFError:
		pass

Measured memory_bytes: 4272
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		boolean[] ac = new boolean[n];
		int[] pe = new int[n];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int p = Integer.parseInt(sa[0]) - 1;
			if (!ac[p]) {
				if ("AC".equals(sa[1])) {
					ac[p] = true;
				} else {
					pe[p]++;
				}
			}
		}
		br.close();

		int ca = 0;
		int cp = 0;
		for (int i = 0; i < n; i++) {
			if (ac[i]) {
				ca++;
				cp += pe[i];
			}
		}
		System.out.println(ca + " " + cp);
	}
}


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

int main(){
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s.at(0) != 'a') {
    cout << "a" << endl;
    return 0;
  }
  
  for(int i = 1; i < s.size();i++){
  	 if(abs(s.at(i) - s.at(i-1)) > 1){
		cout << (char)(s.at(i-1) + 1) << endl;
       return 0;
     }
  }
  
  if(s.at(s.size() -1) != 'z') {
    cout << (char)(s.at(s.size()-1) + 1) << endl;
    return 0;
  }
  
  cout << "None"<< endl;
  
  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    using namespace std;
    using Graph = vector<vector<int>>;

    #define INF 10000000
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    const int dx[4] = {1,0,-1,0};
    const int dy[4] = {0,1,0,-1};
    
    auto seen = vec(bool,500);
    
    void dfs(Graph &G,int v){
      seen[v] = true;

      for(auto nv : G[v]){
        if(seen[nv] == true)continue;
        dfs(G,nv);
      }

    }

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

      int cnt=0;

      rep(i,n-2){
        if(s.substr(i,3) == "ABC")cnt++;
      }
      cout <<cnt;
      }
    
    

    

     

Measured memory_bytes: 256
n,m = map(int,input().split())
ls = list(map(int,input().split()))
a = sum(ls)/4/m
b = 0
for i in range(len(ls)):
    if ls[i] >= a:
        b += 1
    else:
        continue
if b >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;		

bool myfunc(const pair<int,int>& a,const pair<int,int>& b){
	return a.second<b.second || (a.second==b.second && a.first>b.first);
}

int main(){
	int h,n; cin>>h>>n;
	vector<pair<int,int> > p(n);
	ll dp[h+5];
	dp[0]=0;
	
	for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
	sort(all(p),myfunc);
	
	
	
	for(int i=1;i<=h;i++){
		ll menor=1e18;
		for(int j=0;j<n;j++) menor=min((i-p[j].first<0?0:dp[i-p[j].first])+p[j].second,menor);
		dp[i]=menor;
	}
	
	cout<<dp[h];
	
	return 0;
}


Measured memory_bytes: 384
def solve(mid,g):
    for t,d in zip(z[::2],z[1::2]):
        if s[mid]==t:
            mid-=(d<'R')or-1
    return mid==g
n,q,s,*z=open(0).read().split()
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,0):
        ok=mid
    else:
        ng=mid
a=ok
ok=n+1
ng=0
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,n+1):
        ok=mid
    else:
        ng=mid
print(max(0,ok-a-1))

Measured memory_bytes: 136604
#include <stdio.h>
int main(void){
  char s[1001];
  int w,i;
  scanf("%s",s);
  scanf("%d",&w);
  
  for(i=0;s[i]!='\0';i=i+1){
    if(i%w == 0)	putchar(s[i]);
  }
  
  return 0;
}

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

int main(){
    int ans=0,sum=0;
    int m,d;
    
    cin >>m>>d;


    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= d; j++){
            
            if(j%10 >= 2 && (j/10) >= 2 && (j%10)*(j/10)==i)ans++;
        }
        
    }
    
    


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int R = in.nextInt();
            int G = in.nextInt();
            int B = in.nextInt();
            int N = in.nextInt();
            int count = 0;
            for (int r = 0;; r++) {
                if (r * R > N) {
                    break;
                }
                for (int g = 0;; g++) {
                    if (r * R + g * G > N) {
                        break;
                    }

                    if ((N - (r * R + g * G)) % B == 0) {
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 21716
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n: i64 = get();
    let mut x: i64 = get();
    let mut y: i64 = n - x;
    let mut sum : i64 = 0;
    while y != 0 {
        let r = x % y;
        sum += (x / y) * y;
        x = y;
        y = r;
    }
    println!("{}", 3 * sum);
}


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

int n,k,a,b,maxa;

int gcd(int a,int b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

int main() 
{
	cin>>n>>k>>a;
	maxa=a;
	for (int i=2;i<=n;i++)
	{
		cin>>b;
		a=gcd(a,b);
		maxa=max(maxa,b);
	}
	if (k%a==0&&k<=maxa)
		cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int main() {
  int A,B,C,D,E,K;
  cin >> A >> B >> C >> D >> E >> K;
  
  if (E-A<=K){  
  cout << "Yay!" << endl;
  }
  else{
  cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n;
  ll result = 0;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<ll,int>> p;
  for (ll i = 2; i*i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
      p.emplace_back(i, cnt);
  }
  if (n != 1) {
    p.emplace_back(n, 1);
  }

  for (auto x : p) {
    int num = x.second;
    int count = 1;
    while (count <= num) {
      num -= count;
      result++;
      count++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 19732
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

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

void color(int i, int j, int l, int r, const vector<string> &S, map<char,int> &mp, map<vector<vector<int>>, int> &res) {
	if(j >= r) {
		vector<vector<int>> v(2, vector<int>(2));
		v[0][0] = mp[S[0][l]];
		v[0][1] = mp[S[1][l]];
		v[1][0] = mp[S[0][r-1]];
		v[1][1] = mp[S[1][r-1]];
		res[v] = (res[v] + 1) % MOD;
		return;
	}

	if(mp.find(S[i][j]) == mp.end()) {
		set<int> c;
		if(i == 0 && S[i][j] == S[i + 1][j]) {
			c.insert(S[0][j-1]);
			c.insert(S[1][j-1]);
		} else {
			c.insert(S[i][j-1]);
			if(i > 0) c.insert(S[i - 1][j]);
		}
		for(int k = 0; k < 3; ++k) if(c.find(k) == c.end()) {
			mp[S[i][j]] = k;
			color(1-i, j + i %2, l, r, S, mp, res);
			mp.erase(S[i][j]);
		}
	} else {
		color(1-i, j + (i % 2), l, r, S, mp, res);
	}
}

int dp[60][5][5];

signed main(){
	int N;
	cin >> N;
	vector<string> S(2);
	cin >> S[0] >> S[1];
	S[0] = "#" + S[0] + "#";
	S[1] = "#" + S[1] + "#";

	dp[0][0][0] = 1;
	for(int i = 1; i <= N; ++i) {
		for(int j = 0; j <= 3; ++j) for(int k = 0; k <= 3; ++k) {
			if(S[0][i] == S[1][i]) {
				for(int l = 1; l <= 3; ++l) {
					if(l != j && l != k) {
						dp[i][l][l] += dp[i-1][j][k];
						dp[i][l][l] %= MOD;
					}
				}
			} else {
				for(int l = 1; l <= 3; ++l) for(int m = 1; m <=3; ++m) {
					if(l != j && m != k && l != m) {
						dp[i+1][l][m] += dp[i-1][j][k];
						dp[i+1][l][m] %= MOD;
					}
				}
			}
		}
		if(S[0][i] != S[1][i]) {
			++i;
		}
	}
	int res = 0;
	for(int i = 1; i <= 3; ++i) for(int j = 1; j <=3; ++j) {
		res = (res + dp[N][i][j]) % MOD;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,n,l[100],max=0,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
        sum+=l[i];
        if(l[i]>max) max=l[i];
    }
    if(sum-max>max){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
n=int(input())
h=list(map(int,input().split()))

dp=[0 for _ in range(n)]

dp[1]=abs(h[1]-h[0])

for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])  

Measured memory_bytes: 54136
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


a = list()
for _ in range(3):
    a = a + na()
n = ni()
t = [0 for _ in range(9)]
for _ in range(n):
    b = ni()
    for i, ai in enumerate(a):
        if ai == b:
            t[i] = 1

ans = "No"
for i in range(3):
    if t[3 * i] + t[3 * i + 1] + t[3 * i + 2] == 3:
        ans = "Yes"
    if t[0 + i] + t[3 + i] + t[6 + i] == 3:
        ans = "Yes"
if t[0] + t[4] + t[8] == 3:
    ans = "Yes"
if t[2] + t[4] + t[6] == 3:
    ans = "Yes"
print(ans)


Measured memory_bytes: 3444
x=int(input())
a=1000
b=100
li=[]
ans=0

for i in range(1,a+1):
    for j in range(2,b+1):
        if i**j <=1000:
            li.append(i**j)

for j in range(1,x+1):
    if j in li:
        ans=j

print(ans)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

class CGacha {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);


        int n;
        cin >> n;

        set<string> s;
        for (int i = 0; i < n; ++i) {
            string ss;
            cin >> ss;
            s.insert(ss);
        }

        cout << s.size() << endl;
	}
};


int main() {
	CGacha solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 19232
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
    string str,str1;
    cin>>n;
    ll res=0;
    rep(i,1,n+1)
    {
        rep(j,1,n+1)
        {
            rep(k,1,n+1)
            {
                a = __gcd(i, __gcd(j,k));
                res+=a;
            }
        }
    }
    cout<<res;
}

Measured memory_bytes: 3596
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int n = s.length();
    String[] ss = s.split("");
    for (int i = 0; i < n; i++) {
      if(i%2 == 0 )
        System.out.print(ss[i]);
    }
  }
}

Measured memory_bytes: 34996
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
        int x = c - a, y = d - b;
        System.out.println((c - y) + " " + (d + x) + " " + (a - y) + " " + (b + x));
    }
}

Measured memory_bytes: 21844
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

int a[200005];

void Main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int tot = unique(a, a + n) - a;
  if(n == tot) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	ll n,T;cin>>n>>T;
	ll t[n],sum=T;
	rep(i,n) cin>>t[i];

	rep(i,n-1){
		if(t[i+1]>t[i]+T) sum+=T;
		else sum+=t[i+1]-t[i];
	}

	cout<<sum<<endl;
}

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

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    if(a > b){
        ans = ans + a;
        a--;
    }else{
        ans = ans + b;
        b--;
    }

    if(a > b){
        ans = ans + a;
        a--;
    }else{
        ans = ans + b;
        b--;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  int n,m;
  cin >> n >> m;
  vpi ab(n),cd(m);
  REP(i,n) {
    int a,b;
    cin >> a >> b;
    ab[i]=pi(a,b);
  }
  REP(i,m) {
    int c,d;
    cin >> c >> d;
    cd[i]=pi(c,d);
  }
  REP(i,n) {
    pi x=ab[i];
    int a=x.first,b=x.second;
    int cnt=5*pow(10,8);
    int ans=0;
    REP(j,m) {
      pi y=cd[j];
      int c=y.first,d=y.second;
      int temp=abs(a-c)+abs(b-d);
      if(temp<cnt) {
        cnt=temp;
        ans=j+1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, M; cin >> N >> M;
	vector<ll> H(N+1); 
	for (int i = 1; i <= N; i++) cin >> H[i];
	vector<ll> A(M), B(M); 
	rep(i, M) cin >> A[i] >> B[i];

	vector<ll> c(N + 1);
	rep(i, M) {
		if (H[A[i]] > H[B[i]])c[B[i]] = 1;
		else if (H[A[i]] < H[B[i]]) c[A[i]] = 1;
		else {
			c[A[i]] = 1;
			c[B[i]] = 1;
		}
	}

	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		if (c[i] == 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 14348
#include <cstdio>
#include <iterator>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234567;
LL a[MAXN];
int bit[MAXN];

int query(int x) {
    int sum = 0;
    while (x > 0) {
          sum += bit[x];
          x -= (x & (-x));
    }
    return sum;
}

void add(int x, int val, int N) {
     while (x <= N) {
           bit[x] += val;
           x += (x & (-x));
     }
}

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    vector<LL> line;
    for (int i = 1; i <= N; i++) {
        int tmp;
        scanf("%d", &tmp);
        a[i] = a[i - 1] + tmp - K;
    }
    for (int i = 0; i <= N; i++) line.push_back(a[i]);
    sort(line.begin(), line.end());
    line.erase(unique(line.begin(), line.end()), line.end());
    LL ans = 0;
    for (int i = 0; i <= N; i++) {
        int cur = lower_bound(line.begin(), line.end(), a[i]) - line.begin() + 1;
        ans += query(cur);
        add(cur, 1, N + 1);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4336
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int n,m,t,p;
vector<int> p3(8,1);
vector<int> from,to;;
typedef ll Cost;
struct Edge{int to,cap,rev;Cost cost;};
ostream& operator<<(ostream &os,const Edge &e){
  return os<<"{"<<e.to<<","<<e.cost<<"}";}
typedef vector<Edge> Edges;
typedef vector<vector<Edge> > Graph;
typedef pair<Cost,int> Que;

void add_edge(Graph &g,int from,int to,Cost cost,int cap=0){
  g[from].pb((Edge){to,cap,(int)g[to].size(),cost});
  g[to].pb((Edge){from,0,(int)g[from].size()-1,cost});
}
Cost INF=5e15;
//dij

Cost dij(Graph &g,int s,vector<Cost> &d){
  priority_queue<Que,vector<Que>,greater<Que> > que;
  int V=g.size();
  d.resize(V);
  fill(all(d),INF);
  d[s]=0;
  que.push(Que(0,s));
  while(!que.empty()){
    Que p=que.top();que.pop();
    int v=p.Y;
    if(p.Y/n==p3[t]-1)
      return p.X;
    if(d[v]<p.X)continue;
    for(int i=0;i<g[v].size();i++){
      Edge e=g[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(Que(d[e.to],e.to));
      }
    }
  }
  return -1;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int i,j,k;
  cin>>n>>m>>t>>p;
  rep(i,6)
    p3[i+1]=p3[i]*3;
  Graph g(n),h(n*p3[t]);
  int a,b,c;
  rep(i,m){
    cin>>a>>b>>c;
    add_edge(g,a-1,b-1,c);
  }
  from.resize(n,-1); to.resize(n,-1);
  rep(i,t){
    cin>>a>>b;
    --a; --b;
    from[a]=i;
    to[b]=i;
  }
  rep(i,p3[t])rep(j,n){
    for(Edge &e:g[j]){
      h[j+n*i].pb(e);
      h[j+n*i].back().to+=n*i;
    }
    if(from[j]>=0 && i/p3[from[j]]%3==0)
      h[j+n*i].pb({j+n*(i+p3[from[j]]),0,0,0});
    if(to[j]>=0 && i/p3[to[j]]%3==1)
      h[j+n*i].pb({j+n*(i+p3[to[j]]),0,0,0});
  }//cout<<g<<h;
  vector<Cost> dd;
  ll d=dij(h,p-1,dd);
  //cout<<dd;
  if(d<0)
    cout<<"Cannot deliver"<<endl;
  else
    cout<<d<<endl;
  return 0;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++) {
        if(S.at(i) + N <= 'Z') {
            S.at(i) += N;
        } else {
            S.at(i) += N-26;
        }
    }
    cout << S << endl;
    return 0;
}

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

 int main() {
 int n;
 string s;
 cin >> n >> s;
 int ans = 0;
 for(int i = 0; i <= n - 3; i++) {
 if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
 }
 cout << ans << endl;

 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 

int main(){
    int n,m; cin >> n >> m;
    cout << ((n+m)*(n+m-1)/2)-n*m << endl;
return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class ConsoleApp1
{
    public static void Main(string[] args)
    {
        var yen = int.Parse(Console.ReadLine());
        var yen_1 = int.Parse(Console.ReadLine());
        var num = yen % 500;
        if (yen_1 < num)
            Console.WriteLine("No");
        else
            Console.WriteLine("Yes");
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll sum=n/(a+b)*(a+b);
    if(n==sum){
        cout<<n/(a+b)*a<<endl;
    }
    else{
        if(n-sum>=a){
            cout<<n/(a+b)*a+a<<endl;
        }
        else{
            cout<<n/(a+b)*a+(n-sum)<<endl;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
a = input().split()
a = list(map(int, a))
Alice = 0
Bob = 0
for i in range(N):
    if i % 2 == 0:
        Alice += a.pop(a.index(max(a)))
    else:
        Bob += a.pop(a.index(max(a)))
print(Alice - Bob)

Measured memory_bytes: 3064
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n];
		long sum=0;
		long ans=0;
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
			sum+=a[i]-n+1;
		}
		if(sum>0){
			long r=0;
			while(ans!=sum){
				sum--;
		long l=-1;
		r=Long.MAX_VALUE/10;
		while(r-l>1){
			long m=(l+r)/2;
			long count=0;
			for(int i=0; i<n; i++){
				count+=Math.max((a[i]-m+sum+n)/(n+1),0);
			}
			if(count<=sum){
				ans=count;
				r=m;
			}else{
				l=m;
			}
		}
			}
			for(int i=0; i<n; i++){
				a[i]=a[i]+sum-(n+1)*(Math.max((a[i]-r+sum+n)/(n+1),0));
			}
		}
		while(true){
			Arrays.sort(a);
			if(a[n-1]<=n-1){
				break;
			}else{
				a[n-1]-=n;
			}
			for(int i=n-2; i>=0; i--){
				a[i]++;
			}
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int gcd(int A, int B) {
	if (B) return gcd(B, A % B);
	return A;
}

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


	int N = getint(), K = getint();
	int g = getint();
	int saidai = g;
	rep(i, N - 1) {
		int a = getint();
		g = gcd(a, g);
		saidai = max(saidai, a);
	}

	if (K % g == 0 && K <= saidai) co("POSSIBLE");
	else co("IMPOSSIBLE");

	Would you please return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#define N 3
#define NN 9
using namespace std;

struct Puzzle{
  int f[NN];
  int space;
  string path;
  bool operator < (const Puzzle &p)const{
    for(int i=0;i<NN;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static int dx[4]={1,0,-1,0};
static int dy[4]={0,1,0,-1};
static char dir[4]={'r','d','l','u'};

bool isTarget(Puzzle p){
  for(int i=0;i<NN;i++)
    if(p.f[i]!=(i+1))return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle>Q;
  map<Puzzle,bool>V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;
  
  while(!Q.empty()){
    u=Q.front();
    Q.pop();
    if(isTarget(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;
  for(int i=0;i<NN;i++){
    scanf("%d",&in.f[i]);
    if(in.f[i]==0){
      in.f[i]=NN;
      in.space=i;
    }
  }
  string ans=bfs(in);
  printf("%lu\n",ans.size());
  return 0;
}





Measured memory_bytes: 30720
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N;
    cin >> N;

    vll A(N);
    rep(i, N) cin >> A[i];

    ll money = 1000LL;
    ll stock = 0;

    rep(i, N)
    {
        money += stock * A[i];
        stock = 0;

        if (i < N - 1 && A[i] < A[i + 1])
        {
            stock = money / A[i];
            money %= A[i];
        }
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3644
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.chomp.to!int).array;

    long ans;

    foreach_reverse (i ; 0 .. n) {
        if (a[i] > i) {
            writeln(-1);
            return;
        }
        if (i == n - 1) {
            ans += a[i];
            continue;
        }

        if (a[i] == a[i+1] - 1) {
            continue;
        }
        else if (a[i+1] - a[i] > 1) {
            writeln(-1);
            return;
        }
        else {
            ans += a[i];
        }
    }

    writeln(ans);
}













































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 4092
#include <stdio.h>
#include <iostream>
using namespace std;

void printout_array(int* A, int N){
    for(int i = 0; i < N; i++){
        printf("%d", A[i]);
        if(i != N - 1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
}

int bubbleSort(int* A, int N){
    int flag = 1;
    int count = 0;
    while(flag){
        flag = 0;
        for(int j = 1; j < N; j++){
            if(A[j] < A[j - 1]){
                swap(A[j], A[j - 1]);
                flag = 1;
                count += 1;
            }
        }
    }
    return count;
}

int main(void){
    int N;
    scanf("%d", &N);

    int array[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &array[i]);
    }

    int count = bubbleSort(array, N);
    printout_array(array, N);
    printf("%d\n", count);

}



Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair <int,int> p;
typedef vector<int> vi;
#define inf 1000000000
const int max_N=1e5+10;
int h,w,d,q;
vector<p> mas(900005);
vector<ll> need(900005);
ll ans=0;
int main()
{
  cin >> h >> w >> d;
  for(int i=1;i<=h;i++)
    {
      for(int j=1;j<=w;j++)
	{
	  int a;
	  cin >> a;
	  mas[a]=p(i,j);
	}
    }
  need[0]=0;
  for(int i=d;i<=h*w;i+=d)
    {
      for(int j=0;j<d;j++)
	{
	  need[i+j]=need[i+j-d]+abs(mas[i+j].first-mas[i+j-d].first)+abs(mas[i+j].second-mas[i+j-d].second);
	}
    }
  cin >> q;
  for(int i=0;i<q;i++)
    {
      int l,r;
      cin >> l >> r;
      cout << need[r]-need[l] << endl;
    }
  return 0;
}
 


Measured memory_bytes: 15232