akhauriyash/Code-Regression huggingface dataset:
import math

N = int(input())
lis = list(range(1, 10))
start_idx = 0
found = False
while start_idx < len(lis):
    if found:
        break
    idx = start_idx
    for idx in range(len(lis)):
        if lis[start_idx] * lis[idx] == N:
            found = True
    start_idx += 1
if found:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    let mut ans = "".to_string();
    for _ in 0..s.len() {
        ans.push_str("x");
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final String N = sc.next();
        
        int total = N.codePoints().map(c -> c - '0').sum();
        System.out.println(total % 9 == 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 40728
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
 
		String InStr = scan.nextLine();
		String[] AryStr = InStr.split(" ");
 
		int A;
		int B;
		int C;
		int D;
 
		A = Integer.parseInt(AryStr[0]);
		B = Integer.parseInt(AryStr[1]);
		C = Integer.parseInt(AryStr[2]);
 
		if ( A > B ) {
                     D = A;
                     A = B;
                     B = D;
                }
		if ( (A <= C) && (C <= B)) {
                    System.out.println("Yes");
                } else { 
                    System.out.println("No");
                }
	}
}

Measured memory_bytes: 23764
//import java.lang.Math;
import java.util.*;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;
 
public class Main{
	
	
	
	@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
	public static void main(String[] arg) {
		
		
		Map map=new HashMap();
		 Scanner sc = new Scanner(System.in);
	        int cnt = sc.nextInt();
	        for (int i = 0; i < cnt; i++) {
	        
	        int cmt=sc.nextInt();
	        
	        switch(cmt){
	        
	        
	        case 0:
	        	  String str=sc.next();
	              int num=sc.nextInt();
	        
	               map.put(str,num);
	            break;
	        case 1:
	        	str=sc.next();
	        	System.out.println(map.get(str));
	        	break;
	        }
	      
	        
	        }
		
		
		
		
}
	
	
}


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

void solveA(){
  int a,b;
  cin >> a >> b;

  if (b%a==0){
    cout << a+b << endl;
  }
  else {
    cout <<b-a << endl;
  }
}
void solveB(){
  int n,m,k,a;
  cin >> n >> m;
  int cnt[m+1]={0};
  int ans = 0;

  for(int i=0; i<n; i++){
    cin >> k;
    for(int j=0;j<k;j++){
      cin >>a;
      cnt[a]++;
    }
  }

  for(int i=0;i<m+1;i++){
    //    cout << cnt[i] << endl;
    if (cnt[i]==n) ans++;
  }
  cout << ans << endl;
}
void solveC(){
  int n;
  cin >> n;
  int a[n];

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

  int ans=1000000000;

  for (int i=0;i<n-1;i++){
    for (int j=i+1;j<n;j++)
      {
	int anss = a[j]%a[i];
	ans = min(ans,anss);
      }
  }
  
  if (ans==0){
    cout << a[0] << endl;
  }
  else{
    cout << 1 << endl;
  }


  
}
int gcd(int a,int b){
  int r,tmp;

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

void solveD(){
  int n;
  cin >> n;
  int a[n];

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

  int cnt=0;
  int ans;

  ans=gcd(a[0],a[1]);
  for (int i=1;i<n;i++){
    ans=gcd(ans,a[i]);
  }
  
    cout << ans << endl;
}

int main(){
  solveD();
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n, k;
    cin >> n >> k;
    int l[n];
    rep(i, n) cin >> l[i];
    sort(l, l + n, greater<int>());
    int ans = 0;
    rep(i, k) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W, M;
  cin>>H>>W>>M;
  map<int, int> tate, yoko;
  vector<int> tatearr, yokoarr;
  int h, w;
  map<pair<int, int>, int> amap;
  for(int i=0;i<M;++i) {
    cin>>h>>w;
    h--;
    w--;
    if(tate[h]==0) tatearr.push_back(h);
    if(yoko[w]==0) yokoarr.push_back(w);
    amap[mp(h, w)]++;
    tate[h]++;
    yoko[w]++;
  }
  int maxh=0, maxw=0;
  for(int i=0;i<tatearr.size();++i) {
    maxh = max(maxh, tate[tatearr[i]]);
  }
  for(int i=0;i<yokoarr.size();++i) {
    maxw = max(maxw, yoko[yokoarr[i]]);
  }
  vector<int> harr, warr;
  for(int i=0;i<tatearr.size();++i) {
    if(tate[tatearr[i]]==maxh) harr.push_back(tatearr[i]);
  }
  for(int i=0;i<yokoarr.size();++i) {
    if(yoko[yokoarr[i]]==maxw) warr.push_back(yokoarr[i]);
  }
  int ans = maxh+maxw;
  bool ari = true;
  for(int i=0;i<harr.size();++i) {
    for(int j=0;j<warr.size();++j) {
      if(amap[mp(harr[i], warr[j])]==0) {
        ari = false;
        break;
      }
    }
    if(!ari) break;
  }
  if(ari) ans--;
  cout<<ans<<endl;
}



Measured memory_bytes: 56616
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n, a, b;
    cin >> n >> a >> b;

    cout << min(a * n, b) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[][] ab = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).Reverse().ToArray();
        long incr = 0;
        for (int i = 0; i < ab.Length; i++)
        {
            int a = ab[i][0];
            int b = ab[i][1];
            incr += (b - ((a + incr) % b)) % b;
        }
        Console.WriteLine(incr);
    }
}

Measured memory_bytes: 27572
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int X = 0;
  for (int i = 0; i < N; i++) {
    int A, K;
    cin >> A >> K;
    while (A % K != 0 && A >= 2 * K) {
      int m = A / K;
      int l = (A - K * m + m) / (m + 1);
      A -= (m + 1) * l;
    }
    if (A % K == 0) {
      X ^= A / K;
    } else if (K < A) {
      X ^= (A - K + 1) & 1;
    }
  }
  cout << (X != 0 ? "Takahashi" : "Aoki") << '\n';
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>

typedef long long ll;
ll calcC(ll num){
    if(num>1){
        return (num*(num-1))/2;
    }else{
        return 0;
    }
}

int main()
{
    ll n;
    cin>>n;

    vector<ll> count(n);
    vector<ll>a(n);

    for(ll i=0;i<n;i++){
        ll ai;
        cin>>ai;
        a[i]=ai;
        count[ai-1]+=1;
    }

    vector<ll> Cs(n);
    ll base_sum=0;
    for(ll i=0;i<n;i++){
        ll calculated=calcC(count[i]);
        Cs[i]=calculated;
        /*cout<<"Cs["<<i<<"]"<<calculated<<endl;*/
        base_sum+=calculated;
    }

    vector<ll>kekka(n);
    vector<bool>yatta(n);
    
    for(int i=0;i<n;i++){
        yatta[i]=false;
    }

    for(ll k=0;k<n;k++){
        ll ak=a[k];

        if(yatta[ak-1]==true){
            cout<<kekka[ak-1]<<endl;
        }else{
        ll sum=base_sum;
        sum-=Cs[ak-1];
        sum+=calcC(count[ak-1]-1);
        /*cout<<"C:"<<calcC(count[ak-1]-1)<<endl;*/
        cout<<sum<<endl;

        kekka[ak-1]=sum;
        yatta[ak-1]=true;
        }
    }

    return 0;
}

Measured memory_bytes: 9088
//Md Fahad
// CSE 18

#include<bits/stdc++.h>


using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif


typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void){

    int n;
    cin >> n;
    ll sum=0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3640
//初めての尺取り

#include<stdio.h>
#include<iostream>
using namespace std;

#define GOMAE (long long)50000
#define EPS (long long)4000
#define TO_OUTSIDE (long long)1500
#define IS_NOT_EVEN_HOBBY (long long)573
int N;
long long input;
long long A[300010];
long long ans;

//A[i]-A[st] >= A[ed]-A[i]となる最小のiを返す。
int seach1( int st, int ed, int i ){
	
	for( ; i < ed; i++ ){
		if( A[i]-A[st] >= A[ed]-A[i] )
			break;
	}
	return i;
}
//A[i]-A[st] >= Xとなる最小のiを返す。
int seach2( int st, int ed, long long X, int i ){
	
	for( ; i < ed; i++ ){
		if( A[i]-A[st] >= X )
			break;
	}
	return i;
}

int solve( long long X ){
	int i,j=0,k=0;
	
	if( X >= (A[N]>>1) )
		return 0;
	for( i = 0; i < N; i++ ){
		//大きさがX以上になるように切る
		j = seach2(i,N+i,X,j);
		//できるだけ真ん中で切る
		k = seach1(j,N+i,k);
		if( min( A[j]-A[i], min( A[k]-A[j], A[i+N]-A[k] ) ) >= X )
			break;
		k--;
		if( min( A[j]-A[i], min( A[k]-A[j], A[i+N]-A[k] ) ) >= X )
			break;
	}
	if( i < N )
		return 1;
	return 0;
}
				
int main(){
	int i,j,k;
	long long s = 0, e = GOMAE * EPS * TO_OUTSIDE * IS_NOT_EVEN_HOBBY * EPS;
	scanf("%d",&N);
	if( N > 100000 )
		return 0;
		
	for( i = 1; i < N+1; i++ ){
		scanf("%d",&input);
		A[i] = A[i-1]+input;
	}
	for( i = N+1; i < 3*N+1; i++ ){
		A[i] = A[i-N] + A[N];
	}
	
	//printf("%lld %lld\n",s,e);
	while( s <= e ){
		ans = (s+e)>>1;
		if( solve(ans) ){
			if( solve(ans+1) )
				s = ans+1;
			else
				break;
		}
		else{
			e = ans-1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3532
class Dice:
    def __init__(self, usr_input, command):
        self.eyes = list(map(int, usr_input.split()))
        self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
        self.com = list(command)

    def roll(self):
        for c in self.com:
            self.eyes = [n for n in self.pos.values()]
            if c == 'E':
                self.pos[1] = self.eyes[3]
                self.pos[3] = self.eyes[0]
                self.pos[4] = self.eyes[5]
                self.pos[6] = self.eyes[2]
            elif c == 'N':
                self.pos[1] = self.eyes[1]
                self.pos[2] = self.eyes[5]
                self.pos[5] = self.eyes[0]
                self.pos[6] = self.eyes[4]
            elif c == 'S':
                self.pos[1] = self.eyes[4]
                self.pos[2] = self.eyes[0]
                self.pos[5] = self.eyes[5]
                self.pos[6] = self.eyes[1]
            elif c == 'W':
                self.pos[1] = self.eyes[2]
                self.pos[3] = self.eyes[5]
                self.pos[4] = self.eyes[0]
                self.pos[6] = self.eyes[3]

    def top_print(self):
        print(self.pos.get(1))

if __name__ == '__main__':
    dice1 = Dice(input(), input())
    dice1.roll()
    dice1.top_print()

Measured memory_bytes: 7824
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

//最大公約数
ll gcd(ll a,ll b){
    if(b == 0LL) return a;
    return gcd(b , a % b);
}

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

}

int main(){
    int n;
    cin >> n;
    int n_b = n-1;
    vector<int> b(n_b + 2,0);
    for(int i = 1;i < n_b + 1;i++) cin >> b[i];
    b[n_b + 1] = b[n_b];
    b[0] = b[1];

    vector<int> a(n);
    int sum = 0;
    for(int i=0;i < n;i++){

        a[i] = min(b[i],b[i + 1]);
        sum += a[i];
    }

    cout << sum << endl;




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

long double dp[21][201000];
ll N;
ll a[20];

void update(int idx) {
    for(int before = 1; before <= 2e5; before++) {
        for(int after = before; after <= 2e5; after += before) {
            long double delta = abs(after - a[idx]);
            chmin(dp[idx+1][after], max(dp[idx][before], delta / a[idx]));
        }
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= 2e5; j++) {
            dp[i][j] = 1e8;
        }
    }
    dp[0][1] = 0;
    for(int i = 0; i < N; i++) {
        update(i);
        //for(int j = 1; j <= 30; j++) cerr << dp[i+1][j] << " ";
        //cerr << endl;
    }
    long double ans = 1e18;
    for(int i = 1; i <= 2e5; i++) {
        chmin(ans, dp[N][i]);
    }
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}


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

int main(){

    vector<int> a(3);
    int i,sum=0;
    int moto;
    cin >> moto;
    a.at(2) = moto/100;
    a.at(1) = moto/10-10*a.at(2);
    a.at(0) = moto%10;
    for(i=0;i<3;i++){
        if(a.at(i)==1){
            sum++;
        }
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*i-=-1*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn int
#define ll long long 
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define mod 1000000007
#define globalbool 2000000
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
using namespace std::chrono;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	auto start = high_resolution_clock::now();
	int n,k;
	cin>>n>>k;
	int A[n];
	in(n)
		cin>>A[i];
	sort(A,A+n);
	reverse(A,A+n);
	cout<<accumulate(A+min(k,n),A+n,0ll);
	auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start); 
  
    //cout << "Time taken by function: "
    //<< duration.count() << " microseconds" << endl;
}

Measured memory_bytes: 1920
n, k = map(int, input().split())
d = list(map(int, input().split()))

allowed = {i for i in range(10) if i not in d}

MAXN = 10 ** 5


def answer():
    for k in range(1, MAXN + 1):
        if k >= n and all(int(c) in allowed for c in str(k)):
            return k


answer = answer()
print(answer)







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

int main(){
    string S;
    cin >> S;
    int children[100010]={0};
    int n=S.length();
    int i,j;

    for(i=0; i<n-1; i++){
        if(S[i]=='R'&& S[i+1]=='L'){
            children[i]++;
            children[i+1]++;
            j=i-1;
            while(j>=0){
                if(S[j]=='R') children[i+1]++;
                else break;
                j--;
                if(j>=0){
                    if(S[j]=='R') children[i]++;
                    else break;
                }
                j--;
            }
            j=i+2;
            while(j<=n-1){
                if(S[j]=='L') children[i]++;
                else break;
                j++;
                if(j<=n-1){
                    if(S[j]=='L') children[i+1]++;
                    else break;
                }
                j++;
            }
        }
    }

    for(i=0; i<n-1; i++){
        cout << children[i] << ' ';
    }
    cout << children[n-1] << endl;

    return 0;
}

Measured memory_bytes: 4124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const ll INF = (ll) 4e18;

void die() {
    cout << -1 << endl;
    exit(0);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    fori (i, 0, n + 1) cin >> a[i];
    if (a[0] > 1) die();
    if ((a[0] == 0 and n == 0) or (a[0] == 1 and n > 0)) die();
    vector<ll> max_internal(n + 1);
    max_internal[0] = 1;
    fori (i, 1, n + 1) {
        if (2 * max_internal[i - 1] < a[i]) die();
        max_internal[i] = min<ll>(INF, 2 * max_internal[i - 1] - a[i]);
    }
    ll ans = a[n];
    ll v = a[n];
    ford (i, n - 1, 0) {
        ll max_need = min(max_internal[i], v);
        v = max_need + a[i];
        ans += v;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 4692
INF=1000000000
n,k=gets.split.map(&:to_i)
h=gets.split.map(&:to_i)

dp=Array.new(1000000,INF)


dp[0]=0
dp[1]=(h[1]-h[0]).abs
for i in 2..h.length-1

dp_i=[]
for j in 1..k
    if j>i
          break
    end
 
 dp_i<<[dp[i-j]+(h[i-j]-h[i]).abs,dp[i]].min
end
dp[i]=dp_i.min
end
#p dp[0..10]
p dp[h.length-1]

Measured memory_bytes: 89628
N = int(input())
high_list = list(map(int,input().split()))
l = high_list[0]
count = 0
for i in range(N-1):
    i_a = high_list[i]
    i_b = high_list[i+1]
    if(i_a > i_b):
        dai = i_a - i_b
        i_b = i_b + dai
        high_list[i+1] = i_b
        count += dai
print(count)

Measured memory_bytes: 32240
#include<bits/stdc++.h>
#include<set>
using namespace std;
int main(){
  int n;
  cin>>n;
  set<string>s;
  for(int i=0;i<n;i++){
    string str;
    cin>>str;
    s.insert(str);
    }
  cout<<s.size()<<endl;
  }

Measured memory_bytes: 19204
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;

#define ull unsigned long long
#define ll long long
#define PI 3.141592654

int main(){
	int n;
	while(cin>>n,n){
		int tot = 0;
		int  i = 5;
		while( i <= n){
			tot += n/i;
			i *= 5;
		}
		cout<<tot<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
int a[N];
int cnt[N];
int b[N]; 
bool cmp(int a,int b){    return a < b;} 
int main()
{    
	int n;
	while(cin >> n)
	{        
		memset(cnt,0,sizeof(cnt));        
		int j = 0;        
		for(int i=0; i<n; i++){	
			cin >> a[i];            
			cnt[a[i]] ++;            
			if(cnt[a[i]] == 1)                
			b[j++] = a[i];        
		}        
		if(j == 1){
			cout << n << endl;            
			continue;        
		}        
		sort(a,a+n,cmp);        
		sort(b,b+j,cmp);       
		int maxx = 0;        
		int sum = 0;        
		for(int i=a[0]; i<a[n-1]; i++){            
			sum += cnt[i] + cnt[i+1] + cnt[i+2];            
			if(maxx < sum){
				maxx = sum; 
			}                        
			sum = 0;        
		}        
		cout << maxx << endl;    
	}    
			return 0;
}


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

using ll = long long;
const int INF = 1e9 + 1;


int main(){

	int N; cin >> N;
	vector<int>P(N);
	vector<int>Q(N);

	int ka[9] = { 1,1,1,1,1,1,1,1,1 };
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j <= i; j++)
			ka[i] *= j;
	}

	ll ans[2];

	rep(aaa, 2) {
		rep(i, N)
			cin >> P[i];

		vector<bool>num(N + 1);
		ll dicP = 1;
		for (int i = 0; i < N - 1; i++) {
			int a = 0;
			for (int j = 1; j < P[i]; j++)
				if (!num[j])
					a++;
			num[P[i]] = true;

			dicP += ka[N - i - 1] * a;
		}

		ans[aaa] = dicP;
	}

	cout << abs(ans[0] - ans[1]) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a==b){System.out.println("Draw");}
        else{
            if(a>b){
                if(b==1){System.out.println("Bob");}
                else{System.out.println("Alice");}
            }
            else{
                if(a==1){System.out.println("Alice");}
                else{System.out.println("Bob");}
            }
        }
    }
}

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

typedef long long LL;

const int N=100000;

int n,m;

void into(){
  scanf("%d%d",&n,&m);
}

int ans[N+9][3],ca;

void Get_ans(){
  if (n<2*m-1) return;
  int p0=0,p1=n-1>>1;
  for (;p0<n;p0+=2,--p1) ans[++ca][0]=m+p0,ans[ca][1]=m+n+p1,ans[ca][2]=m+n*2+ca-1;
  p0=1;p1=n-1;
  for (;p0<n;p0+=2,--p1) ans[++ca][0]=m+p0,ans[ca][1]=m+n+p1,ans[ca][2]=m+n*2+ca-1;
}

void work(){
  Get_ans();
}

void outo(){
  if (n<2*m-1) puts("-1");
  else
	for (int i=1;i<=n;++i)
	  printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4964
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int a,b,c,x,ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
     if(500*i+100*j+50*k==x) ans++;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int main(){
	for(int i=2;i<50000;i++){
		bool ok=1;
		for(int j=0;j<v.size();j++){
			if(i%v[j]==0)ok=0;
		}
		if(ok)v.push_back(i);
	}
	int m,a,b;
	while(cin>>m>>a>>b&&m){
		int p=-1,q=0;
		for(int i=0;i<v.size();i++){
			for(int j=i;j<v.size();j++){
				if(v[i]*v[j]>m)break;
				if(v[j]<=b*v[i]/a){
					if(p*q<v[i]*v[j])p=v[i],q=v[j];
				}
			}
		}
		cout<<p<<" "<<q<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
import java.util.*
import java.math.*

fun main(args: Array<String>) {
    var (R, G, B, N) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val S = readLine()!!
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var ans = 0
    var count = 0

    for (i in 0..N/R) {
        val r = i*R
        for (j in 0..N/G) {
            val rg = r+j*G
            if (rg > N) break
            if ((N-rg)%B == 0) ans++
        }
    }

    println(ans)
}


Measured memory_bytes: 36084
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.function.Predicate;

public class Main {

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

		int n = sc.nextInt();
		long k = sc.nextLong();
		Integer a[] = new Integer[n];
		Integer f[] = new Integer[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			f[i] = sc.nextInt();
		}

		Arrays.sort(a);
		Arrays.sort(f, Collections.reverseOrder());

		long l = -1;
		long r = (long) Math.pow(10, 12);

		while (l + 1 < r) {
			long c = (l + r) / 2;

			Predicate<Long> checker = (x) -> {
				long s = 0;
				for (int i = 0; i < n; i++) {
					s += Math.max(0, a[i] - x / f[i]);
				}
				return s <= k;
			};

			if (checker.test(c)) {
				r = c;
			} else {
				l = c;
			}
		}
		System.out.println(r);

	}

}


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

using namespace std;

int n;
vector <int> a, sol;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i){
	int x;
	cin >> x;
	a.push_back(x);
}
for(int i = 0 ; i < n ; ++i){
	if(a[i] > i + 1){
		cout << -1 << endl;
		return 0;
	}
}
for(int i = 0 ; i < n ; ++i){
	for(int j = n - i - 1 ; j >= 0 ; --j){
		if(a[j] == j + 1){
			sol.push_back(a[j]);
			a.erase(a.begin() + j);
			break;
		}
	}
}
reverse(sol.begin(), sol.end());
for(int i = 0 ; i < n ; ++i){
	cout << sol[i] << endl;
}

return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 523450
#endif

int N,M;
vector<int> C(SIZE);

template<typename T> class ST {
    using F = function<T(T, T)>;
    int size;
    T init;
    F f;
    vector<T> seg;
    int depth = 0;
    
public: ST(int size, T init, F f): size(size), init(init), f(f) {
    while (1<<depth < size) depth++;
    seg.assign(2<<depth, init);
}
    
    void update(int k, T t) {
        k += 1 << depth;
        seg[k] = t;
        while(k>>=1) seg[k] = f(seg[2*k], seg[2*k+1]);
    }
    
    T query(int a, int b) {
        a += 1<<depth;
        b += 1<<depth;
        T l = init;
        T r = init;
        while(a < b) {
            if (a & 1) l = f(l, seg[a++]);
            if (b & 1) r = f(r, seg[--b]);
            a >>= 1;
            b >>= 1;
        }
        return f(l, r);
    }
    
    T operator[] (int k) {
        return seg[k + (1<<depth)];
    }
};

void solve(int _t) {
    int Q;
    cin>>N>>Q;
    REP(i,N) {
        cin>>C[i];
        C[i]--;
    }
    int l,r;
    vector<pair<int,int>> V,V2;
    REP(i,Q) {
        cin>>l>>r;
        V.push_back({--l,--r});
        V2.push_back({l,r});
    }
    sort(ALL(V));
    vector<int> last(N,-1), prev(N);
    RREP(i,N) {
        prev[i]=last[C[i]];
        last[C[i]]=i;
    }
    auto st = ST<int>(N,0,[](int a, int b){return a+b;});
    map<pair<int,int>,int> ans;
    RFOR(i,V[0].first,N) {
        st.update(i, 1);
        if (prev[i]>=0) {
            st.update(prev[i], 0);
        }
    }
    int s = V[0].first;
    for (auto p:V) {
        while(s<p.first) {
            st.update(prev[s], 1);
            s++;
        }
        ans[p] = st.query(p.first, p.second+1);
    }
    for (auto p:V2) {
        out("%lld\n",ans[p]);
    }
}
EXEC(1)



Measured memory_bytes: 70800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,y;cin >> n >> y;
	rep(i,n + 1){
		if(i * 10000 > y) break;
		rep(j,n + 1){
			if(i * 10000 + j * 5000 > y) break;
			int k = (y - i * 10000 - j * 5000) / 1000;
			if(i + j + k == n){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

bool Y_check(int tmp){
  if(tmp >= 0 && tmp<=99) return true;
  return false;
}

bool M_check(int tmp){
  if(tmp>=1 && tmp<=12) return true;
  return false;
}

int main(){
  string str;
  cin >> str;

  ll before = (str[0]-'0')*10 + (str[1]-'0');
  ll after  = (str[2]-'0')*10 + (str[3]-'0');

  ll YM_flag = (Y_check(before) && M_check(after));
  ll MY_flag = (Y_check(after) && M_check(before));

  if(YM_flag && MY_flag){
    cout << "AMBIGUOUS\n";
  }else if(YM_flag){
    cout << "YYMM\n";
  }else if(MY_flag){
    cout << "MMYY\n";
  }else{
    cout << "NA\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main()
{
    ll a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    while(a||b||c||d||e||f)
    {
        a=a+d;
        b=b+e;
        c=c+f;
        vector<int>m;
        m.push_back(a%3);
        m.push_back(b%3);
        m.push_back(c%3);
        ll sum=0;
        int cnt=0;
        int cnt1=0;
        for(int i=0;i<3;i++)
        {
            if(m[i]==2)
                cnt++;
            else if(m[i]==0)
                cnt1++;
        }
        if(cnt==2&&cnt1==1&&(a>=2||b>=2||c>=2))
        {
            a-=2;
            b-=2;
            c-=2;
            sum+=2;
        }
        sum+=a/3+b/3+c/3;
        sum+=min(min(a%3,b%3),c%3);
        
        
        
        cout<<sum<<endl;
        
        cin>>a>>b>>c>>d>>e>>f;
    }
    return 0;
}



Measured memory_bytes: 3124
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
L = list(range(1, M+1))

D = [list(map(int, input().split())) for _ in range(Q)]
ans = []

for p in combinations_with_replacement(L, N):
    tmp = 0
    for a, b, c, d in D:
        if p[b-1]-p[a-1] == c:
            tmp += d
    ans.append(tmp)

print(max(ans))


Measured memory_bytes: 12632
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

int n;
vector<vector<int>> g;
vector<int> dp, s, fact, rev, ans;

int mod_pow(int a, int b) {
    if (!b) return 1;
    if (b % 2) return a * mod_pow(a, b - 1) % MOD;
    int q = mod_pow(a, b / 2);
    return q * q % MOD;
}

int c(int n, int k) {
    return (fact[n] * rev[k] % MOD) * rev[n - k] % MOD;
}

void dfs1(int v, int p = -1) {
    dp[v] = 1;
    for (int u : g[v]) {
        if (u != p) {
            dfs1(u, v);
            dp[v] = (dp[v] * c(s[u] + s[v], s[u]) % MOD) * dp[u] % MOD;
            s[v] += s[u];
        }
    }
    s[v]++;
}

void dfs2(int v, int p = -1, int up = 1) {
    ans[v] = (dp[v] * c(n - 1, s[v] - 1) % MOD) * up % MOD;
    
    vector<int> suffS(g[v].size()), suff(g[v].size());

    int sum = 0;

    for (int i = g[v].size() - 1; i >= 0; i--) {
        suff[i] = i == g[v].size() - 1 ? 1 : suff[i + 1];
        suffS[i] = i == g[v].size() - 1 ? 0 : suffS[i + 1];
        if (g[v][i] == p) continue;
        int u = g[v][i];
        suffS[i] += s[u];
        suff[i] = (suff[i] * c(sum + s[u], s[u]) % MOD) * dp[u] % MOD;
        sum += s[u];
    }

    sum = n - s[v];

    for (int i = 0; i < g[v].size(); i++) {
        if (g[v][i] == p) continue;
        int suf = i == g[v].size() - 1 ? 1 : suff[i + 1];
        int sufS = i == g[v].size() - 1 ? 0 : suffS[i + 1];
        int u = g[v][i];
        int nup = (up * c(sum + sufS, sufS) % MOD) * suf % MOD;
        dfs2(u, v, nup);
        up = (up * c(sum + s[u], s[u]) % MOD) * dp[u] % MOD;
        sum += s[u];
    }
}

void solve() {
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    fact.resize(n + 1);
    rev.resize(n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
    for (int i = 0; i <= n; i++) rev[i] = mod_pow(fact[i], MOD - 2);

    dp.resize(n);
    s.resize(n);
    ans.resize(n);
    dfs1(0);
    dfs2(0);
    for (int i : ans) cout << i << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 23664
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int A, B;
	cin >> A >> B;
	cout << (A + B) % 24 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MN = 200200;
const ll INF = 1e18;
ll st[2][MN*2];
ll n;
void build(int id) {
	for(int i=n-1;i>0;i--) {
		st[id][i] = min(st[id][i<<1],st[id][i<<1|1]);
	}
}
void up(int p, ll v, int id) {
	p += n;
	st[id][p] = min(st[id][p],v);
	for(;p>1;p>>=1) {
		st[id][p>>1] = min(st[id][p],st[id][p^1]);
	}
}
ll qu(int l, int r,int id) {
	ll tot = INF;
	for(l+=n,r+=n;l<r;l>>=1,r>>=1) {
		if(l&1) {
			tot = min(tot,st[id][l++]);
		}
		if(r&1) {
			tot = min(tot,st[id][--r]);
		}
	}
	return tot;
}
ll fq(ll v) {
	return min(qu(v,n,0)-v,qu(0,v,1)+v);
}
void fu(int p, ll v) {
	up(p,v+p,0);
	up(p,v-p,1);
}
ll v[MN];
int main() {
	ll tot = 0;
	ll q,a,b;
	scanf("%lld %lld %lld %lld",&n,&q,&a,&b);a--;b--;
	v[0] = a;
	for(int i=0;i<q;i++) {
		scanf("%lld",&v[i+1]);
		v[i+1]--;
	}
	q++;
	for(int i=0;i<n;i++) {
		st[0][i+n] = INF+i;
		st[1][i+n] = INF-i;
	}
	build(0);build(1);
	fu(b,0);
	for(int i=1;i<q;i++) {
		ll val = abs(v[i]-v[i-1]);
		tot += val;
		ll nu = fq(v[i]);
		fu(v[i-1],nu-val);
	}
	ll ma = INF;
	for(int i=0;i<n;i++) {
		ma = min(ma,st[0][i+n]-i);
	}
	printf("%lld\n",ma+tot);
}

Measured memory_bytes: 8064
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		in.nextLine();
		String[] line = in.nextLine().split(" ");
		StringBuilder sb = new StringBuilder();

		for (int i = 0, max = line.length - 1; i <= max; i++) {
			sb.append(" ").append(line[max - i]);
		}
		System.out.println(sb.delete(0, 1).toString());
	}
}

Measured memory_bytes: 17136
from itertools import combinations
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())
AB = list(list(map(int, readline().split())) for _ in range(n - 1))
m = int(readline())
UV = list(list(map(int, readline().split())) for _ in range(m))

graph = [[] for _ in range(n + 1)]
for i, (a, b) in enumerate(AB):
    graph[a].append((b, i))
    graph[b].append((a, i))


def dfs(s, g):
    kouho = 0
    par = [(0, 0)] * (n + 1)
    stack = []
    stack.append(s)
    while stack:
        v = stack.pop()
        if v == g:
            break
        for u, i in graph[v]:
            if u == par[v][0]:
                continue
            par[u] = (v, i)
            stack.append(u)
    # 経路復元
    p = g
    q, i = par[p]
    while q > 0:
        kouho |= 1 << i
        p = q
        q, i = par[q]
    return kouho


def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)
    c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)
    c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)
    c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)
    return c


sets = [0 for _ in range(m)]

for idx, (u, v) in enumerate(UV):
    sets[idx] = dfs(u, v)
ans = 0
for i in range(1, m + 1):
    kumiawase = list(combinations(range(m), i))
    for kumi in kumiawase:
        temp = 0
        for j in range(i):
            temp |= sets[kumi[j]]
        num = popcnt(temp)
        ans += (-1) ** (i + 1) * (pow(2, n - 1) - pow(2, n - 1 - num))

print(ans)


Measured memory_bytes: 204040
# AOJ 0032 Plastic Board

n_rectangles = n_lozenges = 0
while line = gets
  l1, l2, ld = line.split(",").map(&:to_i)

  if l1 * l1 + l2 * l2 == ld * ld
    n_rectangles += 1
  elsif l1 == l2
    n_lozenges += 1
  end
end

puts n_rectangles, n_lozenges

Measured memory_bytes: 6096
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """ dict() -> new empty dictionary """

    def items(self):
        """ D.items() -> a set-like object providing a view on D's items """
        return dict.iteritems(self)

    def keys(self):
        """ D.keys() -> a set-like object providing a view on D's keys """
        return dict.iterkeys(self)

    def values(self):
        """ D.values() -> an object providing a view on D's values """
        return dict.itervalues(self)


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


def main():
    n, m, c = map(int, input().split())
    b = [int(bi) for bi in input().split()]

    res = 0
    for i in range(n):
        a = map(int, input().split())
        res += int(sum(ai * bi for ai, bi in zip(a, b)) + c > 0)

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28652
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int n, r;
	cin >> n >> r;
	if(n >= 10)
		cout << r << endl;
	else{
		cout << r + ((10-n)*100);
	}
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	string s;
	cin>>s;

	if(s=="Sunny")cout<<"Cloudy"<<endl;
	else if(s=="Cloudy")cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;	
	
	return 0;
}

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

int main(){
	for(int N; cin>>N && N;){
		for(int i=0;; i++){
			if(N==6174){
				cout<<i<<endl;
				break;
			}
			int c[] = {N/1000, (N/100)%10, (N/10)%10, N%10};
			sort(c, c+4);
			int S = 1000*c[0] + 100*c[1] + 10*c[2] + c[3];
			int L = 1000*c[3] + 100*c[2] + 10*c[1] + c[0];
			if(S==L){
				cout<<"NA"<<endl;
				break;
			}
			N = L-S;
		}
	}
}

Measured memory_bytes: 3164