akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, M;
    cin >> N >> M;

    if (N == 1 && M == 1) cout << 1 << endl;
    else if (N == 1) cout << M - 2 << endl;
    else if (M == 1) cout << N - 2 << endl;
    else cout << (M - 2) * (N - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut map = BTreeMap::new();
    for (i, val) in a.iter().enumerate() {
        map.insert(val, i + 1);
    }

    for (&key, val) in map {
        if key == n {
            println!("{}", val);
        } else {
            print!("{} ", val);
        }
    }
}

Measured memory_bytes: 8956
/*
[abc138] B - Resistors in Parallel
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 100;

int N;
int A[MAX_N];

double solve() {
    double b = 0;
    for (int i = 0; i < N; i++) {
        b += 1.0 / A[i];
    }

    double ans = 1.0 / b;

    return ans;
}

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

    cout << setprecision(16) << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [usize1; n],
    }
    let mut v = vec![0; n];
    for (i, ai) in a.into_iter().enumerate() {
        v[ai] = i + 1;
    }
    let ans = v
        .into_iter()
        .map(|vi| vi.to_string())
        .collect::<Vec<_>>()
        .join(" ");
    println!("{}", ans);
}


Measured memory_bytes: 10492
import java.util.Scanner;
 
class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
 
    int input1 = scan.nextInt();
 
    Tree main = new Tree(-2147483648);
 
    for(int loopCount = 0; loopCount < input1; loopCount++) {
      char[] s = scan.next().toCharArray();
      if(s[0]=='i') main.insert(scan.nextInt());
      else if(s[0]=='p') {
        if(main.right != null) {
          main.right.printMiddle();
          System.out.println();
          main.right.printFirst();
          System.out.println();
        }
      }
    }
  }
}
 
class Tree{
  int key;
  Tree left,right;
 
  Tree(int _key) {
    this.key = _key;
  }
 
  void insert(int _num) {
    if(key<_num) {
      if(right == null) {
        right = new Tree(_num);
      }else {
        right.insert(_num);
      }
    }else if(key>_num) {
      if(left == null) {
        left = new Tree(_num);
      }else {
        left.insert(_num);
      }
    }
  }
 
  String find(int _num) {
    if(key == _num) return "YES";
    else {
      if(key > _num) return left.find(_num);
      if(key < _num) return right.find(_num);
      return "NO";
    }
  }
 
  void printFirst() {
    System.out.print(" "+key);
    if(left!=null) left.printFirst();
    if(right!=null) right.printFirst();
  }
 
  void printMiddle() {
    if(left!=null) left.printMiddle();
    System.out.print(" "+key);
    if(right!=null) right.printMiddle();
  }
}

Measured memory_bytes: 229816
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

#include <vector>

// ------ Class ------ //
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

#endif

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[109];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	int p = *min_element(a, a + n), q = *max_element(a, a + n), cp = 0, cq = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == p) cp++;
		if (a[i] == q) cq++;
	}
	if (cp >= 3 || cq == 1) cout << "Impossible" << endl;
	else if (cp == 2 && q >= p * 2) cout << "Impossible" << endl;
	else if (cp == 1 && q < p * 2) cout << "Impossible" << endl;
	else {
		UnionFind uf(n);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (abs(a[i] - a[j]) == 1 || (a[i] == p && a[j] == p)) {
					uf.unite(i, j);
				}
			}
		}
		bool ok = true;
		for (int i = 1; i < n; i++) {
			if (uf.root(0) != uf.root(i)) ok = false;
		}
		cout << (ok ? "Possible" : "Impossible") << endl;
	}
	return 0;
}

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

#define vi vector<int>

int main() {

    string S;
    cin >> S;

    bool easy = true;
    for (int i = 0; i < S.length(); i++) {
        if (i%2 == 0) {
            if (S[i] == 'L') {
                easy = false;
                break;
            }
        }
        else {
            if (S[i] == 'R') {
                easy = false;
                break;
            }
        }
    }

    if (easy) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	for(;;){
		int row[5000];
		cin >>n;
		if(n == 0){break;}
		for(int i=0; i<n; i++){
			cin >>row[i];
		}
		int max = -9999999;
		for(int i=0; i<n; i++){
			int sum = row[i];
			if(max<sum){max = sum;}
			for(int l=i+1; l<n; l++){
				sum+=row[l];
				if(max<sum){max = sum;}				
			}
		}
		cout <<max<<endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int main(){
  int K, N, res;
  rd(N);
  rd(K);
  res =divup_L((N-1),(K-1));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int N, K, res;
//   rd(N,K);
//   res = (N-1) /+ (K-1);
//   wt(res);
// }


Measured memory_bytes: 764
using System;
using System.Collections.Generic;

class IDONTKNOWCSHARP
{
    public static void Main()
    {
        string[] temp = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        int num = int.Parse(temp[0]);
        double distance = double.Parse(temp[1]);
        int count = 0;
        (int x, int y)[] positions = new (int x, int y)[num];

        for (int i = 0; i < num; i++)
        {
            string[] pos = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            positions[i] = (int.Parse(pos[0]), int.Parse(pos[1]));
        }

        foreach (var position in positions)
        {
            if (distance >= Math.Sqrt(Math.Pow(position.x,2) + Math.Pow(position.y, 2)))
            {
                count++;
            }
        }

        Console.WriteLine(count);

    }

}

Measured memory_bytes: 47752
N = list(map(int, input().split()))
A = list(map(int, input().split()))
log = ""

L=max(A)
S=min(A)
A.remove(L)
A.remove(S)
for x in A:
    if x>0:
        log += "\n"+str(S)+" "+str(x)
        S = S-x
    else:
        log += "\n"+str(L)+" "+str(x)
        L = L-x
log += "\n"+str(L)+" "+str(S)
L = L-S
print(str(L)+log)

Measured memory_bytes: 16068
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
public static void main(String[] args)
{
	Scanner sc=new Scanner(System.in);
  int k=sc.nextInt();
  String s=sc.next();
  
  if(s.length()<=k)
    System.out.println(s);
  
  else
  {
		s=s.substring(0,k) +"...";
      System.out.print(s);
    
  }
  
 
}
}


Measured memory_bytes: 38592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc079/tasks/abc079_c

string z;
string OP;

static bool dfs(int sum, string ops) {
    if (ops.length() == 3) {
        OP = ops;
        return sum == 7;
    }

    // dump(z[ops.length()+1])
    if (dfs(sum+(z[ops.length()+1] - '0'), ops+"+")) return true;
    if (dfs(sum-(z[ops.length()+1] - '0'), ops+"-")) return true;
    return false;
}

int main() {
    cin >> z;

    if (dfs(z[0] - '0', "")) {
        printf("%c%c%c%c%c%c%c=7\n", z[0], OP[0], z[1], OP[1], z[2], OP[2], z[3]);
    }

    return 0;
}


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

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
 char a;
  cin >> a;
  if ( a=='a' || a=='i' ||a=='u'||a=='e'||a=='o' ){
    cout <<"vowel";
  }else{
	cout <<"consonant";
  }
}

Measured memory_bytes: 256
#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<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(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()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll n;
  cin>>n; n;
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i]; a[i];
  }
  vector<ll> b(n);
  rep(i,n){
    cin>>b[i]; b[i];
  }
	const ll INF=1e18;
	ll re=INF;
	rep(st,1<<n){
		vector<int> vs(n+1);
		rep(i,n) vs[i]=(st>>i&1?b[i]:a[i]);
		out(st,vs,1);
		vector<int> ind(n); iota(all(ind),0);
		sort(all(ind),[&](int i,int j){ return vs[i]<vs[j];});
		ind.pb(n);
		vector<int> isOdd(n);
		rep(i,n) isOdd[i]=(i+(st>>i&1))%2;
		int prv=-1;
		vector<int> o0,e0,o1,e1;
		int ok=1;
		vector<int> seq(n);
		rep(ii,n+1){
			int i=ind[ii];
			out(ii,i,1);
			if(vs[i]!=prv){
				out(ii,i,o0,o1,e0,e1,1);
				if(o0.size()!=o1.size()||e0.size()!=e1.size()){ ok=0; break;}
				sort(all(o1)); sort(all(e1));
				rep(i,o0.size()) seq[o0[i]]=o1[i];
				rep(i,e0.size()) seq[e0[i]]=e1[i];
				o0.clear(); o1.clear(); e0.clear(); e1.clear();
				prv=vs[i];
			}
			(ii%2?o0:e0).pb(ii);
			(isOdd[i]%2?o1:e1).pb(i);
		}
		out(st,ok,1);
		if(ok){
			ll cnt=0;
			rep(i,n){
				if(cnt>=re) break;
				rep(j,i)if(seq[j]>seq[i]) ++cnt;
			}
			MN(re,cnt);
		}
	}
	cout<<(re==INF?-1:re) NL;
	return 0;
}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/problems/0027

#include <bits/stdc++.h>

using namespace std;

string day[7] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
    int m, d;

    while (true) {
        cin >> m >> d;
        if (m + d == 0) return 0;

        m--;
        d--;
        for (int i = 0; i < m; ++i) {
            d += months[i];
        }
        cout << day[d % 7] << endl;
    }
}

/*
 * 1/1から何日ずれるか数えて7で割る。
 */


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
const int N=15;
const int mod=1e9+7;
typedef long long ll;
int n,m;
int f[1<<16];
int pw[(1<<15)+5];
int e[N];
int main()
{
	scanf("%d%d",&n,&m);
	pw[0]=1;f[0]=1;
	for(int i=1;i<=m;i++)pw[i]=(pw[i-1]<<1)%mod;
	for(int i=1;i<=m;i++){
		int u,v;scanf("%d%d",&u,&v);
		u--,v--;
		e[u]|=(1<<v);
	}
	for(int S=1;S<(1<<n);S++)if((S&1)==((S>>1)&1)){
		for(int T=S;T;T=(T-1)&S)if((T&1)==((T>>1)&1)){
			int ways=1;
			for(int i=0;i<n;i++)if((S>>i)&1){
				if((T>>i)&1)ways=1ll*ways*pw[__builtin_popcount(e[i]&(S^T))]%mod;
				else ways=1ll*ways*(pw[__builtin_popcount(e[i]&T)]-1)%mod;
			}
			f[S]=(f[S]+(ll)f[S^T]*ways)%mod;
			//cout<<T<<">"<<f[S^T]<<endl;
		}
		//cout<<S<<" "<<f[S]<<endl;
	}
	printf("%d\n",(pw[m]-f[(1<<n)-1]+mod)%mod);
}

Measured memory_bytes: 384
function Main(input) {

	input = input.split(" ");
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
if (a>b){
	console.log( 'safe')
} else {
    console.log(  'unsafe')
}

}

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

Measured memory_bytes: 29612
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
#include <map>
using namespace std;
typedef long long ll;

const int INF = 1000000010;
int dp[100010];

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = 0; i < n; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i + j >= n) continue;
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[n-1] << endl;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  int n;
  loop {
    cin >> n;
    if (!cin) break;
    if (!n) break;

    int ac = 0;
    vi xs;
    rep (_, n) {
      int x; cin >> x;
      ac = max(x, ac+x);
      xs.push_back(ac);
    }

    int mx = -INF;
    for (int x:xs) mx = max(x,mx);
    cout << mx << endl;

  }

  return 0;
}

Measured memory_bytes: 1240
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        Queue<Integer> que = new ArrayDeque<>();
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            for (int j = 0; j < a; j++) {
                que.add(i);
            }
        }
        int[][] ans = new int[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans[i][j] = que.poll();
            }
        }
        for (int i = 0; i < H; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < W - 1; j++) {
                    System.out.print((ans[i][j] + 1) + " ");
                }
                System.out.print(ans[i][W - 1] + 1);
            } else {
                for (int j = W - 1; j > 0; j--) {
                    System.out.print((ans[i][j] + 1) + " ");
                }
                System.out.print(ans[i][0] + 1);
            }
            System.out.println();
        }
    }
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
     int n;
     cin>>n;
     if(n%1000==0)
        cout<<0<<endl;
     else
     {
        while(n>=1000)
        {
            n=n%1000;
        }
        cout<<1000-n<<endl;
     }  
     return 0;
}




Measured memory_bytes: 3600
#!ruby -na
f=->n{E[n]||=(*r=E[n]=n*D
[2,3,5].zip(A){|y,a|r<<f[n/y]+a+n%y*D<<f[0--n/y]+a+-n%y*D}
r.min)}
N,*A,D=$F.map &:to_i
E={}
p f[N]if D

Measured memory_bytes: 17800
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
void main() {
        int n=to!int(readln().strip());
        for(int i=0;i<n;i++){
                auto bs=readln().split().map!(to!int)().array();
                int s1=-1,s2=-1;
                bool flag = true;
                for(int j=0;j<10;j++){
                        if(s1<bs[j]&&bs[j]-s1<bs[j]-s2)s1=bs[j];
                        else if(s2<bs[j]&&bs[j]-s1>bs[j]-s2)s2=bs[j];
                        else if(s1<bs[j]) s1=bs[j];
                        else if(s2<bs[j]) s2=bs[j];
                        else {flag=false;break;}
                }
                if(flag) writeln("YES");
                else writeln("NO");
        }
}

Measured memory_bytes: 2448
#! /usr/bin/python
# -*- coding: utf-8 -*-

table = [[],[".",",","!","?"," "],["a","b","c"],["d","e","f"],\
        ["g","h","i"],["j","k","l"],["m","n","o"],["p","q","r","s"],\
        ["t","u","v"],["w","x","y","z"]]

n = int(raw_input())
for i in range(n):
    m = raw_input()
    ans = ""
    pre = '0'
    cnt = 0
    for j in range(len(m)):
        if m[j] == '0':
            if cnt == 0:
                pass
            elif pre == '1':
                ans += (table[1][(cnt-1)%5])
            elif pre == '7' or pre == '9':
                ans += (table[int(pre)][(cnt-1)%4])
            else:
                ans += (table[int(pre)][(cnt-1)%3])
            cnt = 0
        else:
            pre = m[j]
            cnt += 1
    print ans

            


    
    

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

int main() {
  long long n;
  long long ans = 0;
  long long div = 10;
  cin >> n;

  if (n < 2) {
    cout << 0 << endl;
  } else if (n % 2 == 1) {
    cout << 0 << endl;
  } else {
    while (div <= n) {
      ans += n / div;
      div *= 5;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int x, y;
	while(1){
		scanf("%d %d", &x, &y);
		if((x == 0)&&(y == 0)){
			break;
		}
		else{
			if(x < y)
				printf("%d %d\n", x, y);
			else
				printf("%d %d\n", y, x);		}
	}
	return 0;

}


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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;

bool custom1 (pii a, pii b) {
  return (a.first < b.first);
}

bool custom2 (pii a, pii b) {
  return (a.second < b.second);
}

const int MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;

  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
from pprint import pprint

# import math
# import collections

n = int(input())
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
t, x, y = [0], [0], [0]
d = [0]
dd = [0]
td = [0]

for i in range(1, n + 1):
    _t, _x, _y = map(int, input().split(' '))
    t.append(_t)
    x.append(_x)
    y.append(_y)

    d.append(abs(x[i] - x[0]) + abs(y[i] - y[0]))
    dd.append(abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]))
    td.append(t[i] - t[i-1])

# 時刻の奇遇と距離の奇遇は一致する
# d <= t である
movable = [False] * (n + 1)

for i in range(n + 1):
    if d[i] <= t[i] and (t[i] % 2 == d[i] % 2) and dd[i] <= td[i]:
        movable[i] = True

if all(movable):
    res = 'Yes'
else:
    res = 'No'

# pprint(d)
# pprint(movable)
print(res)


Measured memory_bytes: 24892
// Multiple of 9.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
#include <string>

int main()
{
	string s;
	cin >> s;
	long long n = 0;
	for (long long i = 0; i < s.size(); i++){
		n += int(s[i])-48;
		n=n%9;
	}
	if (n%9==0){
		cout << "Yes";
	}
	else { 
		cout << "No";
	}
	return 0;
}



Measured memory_bytes: 3748
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        char[][] map = new char[H][W];
        
        for(int i = 0; i < H; i++) {
            String s = scan.next();
            map[i] = s.toCharArray();
        }
        
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                // System.out.print(map[i][j]);
                if(map[i][j] == '#') System.out.print('#');
                else System.out.print(countMine(i, j, H, W, map));
            }
            System.out.println();
        }
    }
    
    static int countMine(int i, int j, int H, int W, char[][] map) {
        int count = 0;
        if(i != 0 && j != 0 && map[i-1][j-1] == '#') count++; //左上
        if(i != 0 && map[i-1][j] == '#') count++; //上
        if(i != 0 && j != W-1 && map[i-1][j+1] == '#') count++; //右上
        if(j != 0 && map[i][j-1] == '#') count++; //左
        if(j != W-1 && map[i][j+1] == '#') count++; //右
        if(i != H-1 && j != 0 && map[i+1][j-1] == '#') count++; //左下
        if(i != H-1 && map[i+1][j] == '#') count++; //下
        if(i != H-1 && j != W-1 && map[i+1][j+1] == '#') count++; //右下
        
        return count;
    }
}


Measured memory_bytes: 22484
while True:
  n = int(input())
  if n == 0:
    break
  c = 0
  l = []
  d = {}
  for i in range(n):
    num,x,y = [int(i) for i in input().split()]
    if num in d:
      d[num] = d[num] + x*y
    else:
      d[num] = x*y
      l.append(num)
  for i in l:
    if d[i] >= 1000000:
      print(i)
      c += 1
  if c == 0:
    print('NA')


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

using namespace std;

int main()
{
    ll x;
    cin>>x;
    ll a=100;
    ll j=0;
    while(a<x){
        a=a*1.01;
        j++;
    }
    cout<<j;
    cout<<endl;
}


Measured memory_bytes: 3624
while True:
    a0, l = map(int, input().split())
    if a0 == 0 and l == 0: break
    seq = [a0]
    a = str(a0)
    for i in range(20):
        if len(a) < l:
            a = '0' * (l - len(a)) + a
        a_min = int(''.join(sorted(list(a))))
        a_max = int(''.join(sorted(list(a), reverse=True)))
        ai = a_max - a_min
        if ai in seq:
            j = seq.index(ai)
            print(j, ai, (i+1)-j)
            break
        else:
            seq.append(ai)
            a = str(ai)

Measured memory_bytes: 6720
import sys
sys.setrecursionlimit(10**6)

root = list()


def dfs(A, num, N, memo):
    if memo[A[num]-1] == 1:
        return root.index(A[num])
    else:
        root.append(A[num])
        memo[A[num]-1] = 1
        return dfs(A, A[num]-1, N, memo)


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    memo = [0] * N
    start = dfs(A, 0, N, memo)

    if K <= len(root):
        print(root[K-1])
    else:
        index = (K - start) % (len(root)-start)
        loop = root[start:]
        print(loop[index-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 193324
//C - Together: 4Min;
//Assunto: AdHoc;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    map<int, int> show;
    int n, x, maxi = 0;
    
    cin >> n;
    loop(i, 0, n) {
        cin >> x;
        show[x]++;
        show[x+1]++;
        show[x-1]++;
    }
    for(auto x : show) maxi = max(maxi, x.se);
    cout << maxi << "\n";
}

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

int main(){
	int A,B;
	cin>>A>>B;
	int temp =A+B;
	if (temp<A-B){
		temp = A-B;
	}
	if(temp <A*B){
		temp = A*B;
	}
	cout<<temp;

}


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


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

 vector<int> A(N);
 double u = 1,sum;
 for(int i = 0;i < N;i++) {
   cin >> A.at(i);
   u *= A.at(i);
 } 

 sum = u;

 double b = 0;
 
  for(int i = 0;i < N;i++) {
    b += sum / A.at(i);
  }
 
 cout << setprecision(15) << u / b << endl;



}


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

int main() {
	// your code goes here
	int k,x,y,i;
	cin>>k>>x>>y;
	int f=0;
	for( i=x;i<=y;i++){
		if(i%k==0){
			 f=1;
			break;
		}
	}
	if(f==1)
		cout<<"OK"<<endl;
		else
		cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3596
import numpy as np
h,w=map(int,input().split())
s=list(input() for i in range(h))
flag=False
ans="Yes"
for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            flag=False
            for k in[-1,1]:
                if(i+k<h and 0<=i+k and s[i+k][j]=="#"):
                    flag=True
                    break
                if(j+k<w and 0<=j+k and s[i][j+k]=="#"):
                    flag=True
                    break
            if(flag==False):
                ans="No"
                break
        
print(ans)        

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

n = int(input())
a = [int(input()) for i in range(n)]
a_m = a.index(max(a))
am = a[a_m]
del a[a_m]
amm = max(a)
for i in range(n):
    if i != a_m:
        print(am)
    else:
        print(amm)

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

int main()
{
  string S;
  cin >> S;
  int count;
  
  for(int i = 0; i<=4 ;i++){
      if(S[i] == '2') count += 1;
    }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
#define gcd(A,B) __gcd(A,B)
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-12
#define ld long double
#define modulo 998244353
#define tmplarge (lli)1e4
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<int,double> pid;


int n;
int main()
{
    int L[500], ans=0;
    scanf("%d",&n);
    for (int i = 0; i<2*n; i++)
        scanf("%d",L+i);
    sort(L,L+2*n);
    for (int i = 0; i<(2*n-1); i+=2)
        ans += L[i];
    printf("%d",ans);
}

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

int main() {
  int w, a, b, i, ans = 0;
  cin >> w >> a >> b;
  int A = min(a, b), B = max(a, b);
  if (A + w < B) {
    ans = B - A - w;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);

    unsigned long long int s;
    cin >> s;
    unsigned long long int first=ceil(pow(s,0.5));
    // cout << pow(first,2)<< endl;
    // cout << pow(first+1,2) << endl;
    cout << "0 0 ";
    unsigned long long int res=first*first-s;
    // cout << "s: " << s << endl;
    // cout << "tot: " <<  first*first-res << endl;
    unsigned long long int fact;
    if(res<=1e9)
    {
        cout << first << " " << res << " " << 1 << " " << first << endl;
        // cout << -res << endl;
        return 0;
    }
    for(unsigned long long int i=floor(first); i>=0; i--)
    {
        if(!res%i)
            fact=i;
    }
    // cout << "MADE IT HERE..." << endl;
    // cout << first << " " << fact << " " << res/fact << " " << first << endl;
    cout << pow(first,2)-fact*(res/fact) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k,j,i=0,z=0,kotae=0,zeronokazu=0;
  cin >> n >> k;
  char s[n];
  int kiten[n+k+2],shuten[n+k+2];
  cin >> s[0];
  if(s[0]=='1'){
    kiten[0]=0;
    i++;
  }else{
    kiten[0]=0;
    shuten[0]=0;
    i++;
    z++;
    zeronokazu++;
  }
  for(j=1;j<n;j++){
    cin >> s[j];
    if(s[j-1]<s[j]){
      kiten[i]=j;
      i++;
    }else if(s[j-1]>s[j]){
      shuten[z]=j;
      z++;
      zeronokazu++;
    }
  }
  if(s[n-1]=='1'){
    shuten[z]=n;
    z++;
  }else{
    kiten[i]=n;
    shuten[z]=n;
    i++;
    z++;
  }
  for(j=0;j<i-k;j++){
    if(shuten[j+k]-kiten[j]>kotae){
      kotae=shuten[j+k]-kiten[j];
    }
  }
  if(zeronokazu<=k){
    kotae=n;
  }
  cout << kotae << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w; scanf("%d%d", &h, &w);
	auto a = make_v<int>(h, w);
	auto b = make_v<int>(h, w);
	auto c = make_v<int>(h, w);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) scanf("%d", &a[i][j]);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) scanf("%d", &b[i][j]);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) c[i][j] = std::abs(a[i][j] - b[i][j]);

	auto dp = make_v<std::bitset<160 * 80 + 1>>(h, w); dp[0][0][c[0][0]] = true;
	std::vector<int> dx = {0, -1, 0, 1};
	std::vector<int> dy = {1, 0, -1, 0};
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			for(int k = 0; k < 4; k++) {
				int x = i + dx[k], y = j + dy[k];
				if(x < 0 or y < 0 or x >= h or y >= w) continue;
				int val = c[x][y];

				for(int l = 0; l < dp[i][j].size(); l++) {
					if(!dp[i][j][l]) continue;
					
					dp[x][y][std::abs(l + val)] = true;
					dp[x][y][std::abs(l - val)] = true;
				}
			}
		}
	}

	for(int i = 0; i < 160 * 80 + 1; i++) {
		if(!dp[h - 1][w - 1][i]) continue;

		printf("%d\n", i);
		return 0;
	}
	return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<vector>

int main(){
  long long N; std::cin >> N;
  std::vector<long long> v(N);
  for(auto i=0; i<N; ++i)
    std::cin >> v[i];
  std::vector<long long> to(N);
  auto c = 0LL;
  auto s = 0LL;
  for(auto i=0; i<N; ++i){
    s += std::abs(c - v[i]);
    c = v[i];
    to[i] = s;
  }
  std::vector<long long> from(N);
  c = 0LL;
  s = 0LL;
  for(auto i=N-1; i>=0; --i){
    s += std::abs(c - v[i]);
    c = v[i];
    from[i] = s;
  }
  std::vector<long long> r(N);
  r[0] = std::abs(v[1]) + from[1];
  for(auto i=1; i<N-1; ++i)
    r[i] = to[i-1] + std::abs(v[i+1] - v[i-1]) + from[i+1];
  r[N-1] = to[N-2] + std::abs(v[N-2]);

  for(auto i=0; i<N; ++i)
    std::cout << r[i] << '\n';
}


Measured memory_bytes: 4352
A,B,C,X,Y = map(int, input().split())
ans = 0
if (A + B)  >= C * 2:
    if X < Y:
        ans += X * C * 2
        Y -= X
        if B <= C * 2:
            ans += B * Y
        else:
            ans += C * Y * 2
    elif X > Y:
        ans += Y * C * 2
        X -= Y
        if A <= C * 2:
            ans += A * X
        else:
            ans += C * X * 2
    else:
        ans += X * C * 2
else:
    ans += A * X + B * Y

print(ans)


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

int main() {
	int n, w;
	cin >> n >> w;
	vector<int> val(n), weight(n);
	
	for(int i = 0; i < n; i++) {
		cin >> weight[i] >> val[i];
	}
	
	vector<vector<ll>> dp(n+1, vector<ll> (w+1, 0));
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= w; j++) {
			if(weight[i-1] <= j) {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j - weight[i-1]] + val[i-1]);
			}
			else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	
	cout << dp[n][w] << "\n";
}


Measured memory_bytes: 83176
# Problem: https://atcoder.jp/contests/abc091/tasks/abc091_b
# Python 3rd Try

import sys
from collections import defaultdict
# import pprint
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(blue_count, blue_list, red_count, red_list):
    result = 0
    allDict = defaultdict(int)
    for j in range(0, blue_count, +1):
        allDict[blue_list[j]] += 1
    for j in range(0, red_count, +1):
        allDict[red_list[j]] -= 1
    # algorithm
    # print("{}".format(allDict))
    dictList = list(allDict.values()) + [0]
    dictList.sort(reverse=True)
    # pprint.pprint("{}".format(dictList))
    result = dictList[0]
    return result


if __name__ == "__main__":
    N = II()
    si = []
    for _ in range(0, N, +1):
        si.append(input())
    M = II()
    ti = []
    for _ in range(0, M, 1):
        ti.append(input())
    print("{}".format(solver(N, si, M, ti)))


Measured memory_bytes: 9420
open System

let abx = stdin.ReadLine().Split() |> Array.map int |> Array.map float
let [|a;b;x|] = abx


let harf = a * a * b / 2.0
let pat = if x < harf then 1 else 2

let tate1 = (x * 2.0) / (a * b)
let tate2 = ((a * a * b - x) * 2.0) / (a * a)

let rad1 = Math.Atan (tate1 / b)
let rad2 = Math.Atan (tate2 / a)

let f rad = rad * 180.0 / Math.PI

let ans = if (pat = 1) then (90.0 - (f rad1)) else (f rad2)

ans
|>stdout.WriteLine

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

int main() {
  int h,w;
  char a[8][8];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  bool pos = true;
  for (int i = 0, j = 0;;) {
    if (i == h-1 && j == w-1) {
      break;
    }
    if (i == h-1) {
      if (a[i][j+1] == '#') {
        j++; continue;
      } else {
        pos = false; break;
      }
    }
    if (j == w-1) {
      if (a[i+1][j] == '#') {
        i++; continue;
      } else {
        pos = false; break;
      }
    }
    if (a[i+1][j] == a[i][j+1]) {
      pos = false; break;
    }
    if (a[i+1][j] == '#') {
      i++;
    }
    if (a[i][j+1] == '#') {
      j++;
    }
  }
  int sum = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') sum++;
    }
  }
  if (sum != h + w - 1) pos = false;
  if (pos) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	if (N % 1000 == 0) {
		cout << 0 << endl;
		return;
	}
	cout << 1000 - (N % 1000) << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3604
S = list(input())
T = list(input())

S = [ord(s) for s in S]
T = [ord(s) for s in T]

S.sort()
T.sort(reverse=True)

LS = len(S)
LT = len(T)

ok = None
for i in range(min(LS,LT)):
  s = S[i]
  t = T[i]
  if s < t:
    ok = True
    break
  elif s == t:
    continue
  elif t < s:
    ok = False
    break

if ok:
  print('Yes')
elif ok == None:
  if LS < LT:
    print('Yes')
  else:
    print('No')
else:
  print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  vector<int> a;
  a.push_back(s);
  int ans = 1;
  while(true){
    int end =0;
    ans += 1;
    if( s % 2 ==0){
      s = s/2;
    }
    else{
      s = 3*s +1;
    }
    for( int i =0 ;i<a.size();i++){
      if( a.at(i) == s ){
        cout << ans;
        end = 1;
        break;
      }
    }
    if( end == 1){
      break;
    }
    a.push_back(s);
  }
}

Measured memory_bytes: 256
F=lambda:map(int,input().split())
H,W,D=F();d={};e=[0]*H*W
for i in range(H):
 for j,v in enumerate(F()):d[v-1]=(i,j)
for i in range(H*W):
 if i>=D:e[i]=sum(abs(p-q)for p,q in zip(d[i-D],d[i]))+e[i-D]
for i in range(int(input())):l,r=F();print(e[r-1]-e[l-1])

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,l,t,x,y,z;
    scanf("%lld",&n);
    l=0;
    k=0;
    for(i=0;i<n;i++){
        scanf("%lld %lld",&x,&y);
        l+=y;
        m=x*y;
        k+=m;
    }
    m=k/9;
    if(k%9==0)
        m--;
    l--;
    l+=m;
    printf("%lld",l);
}


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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];

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

    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }

    fill(dp, dp + mnx, mod);

    dp[0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 200000; j >= b[i]; j--) {
            if(dp[j - b[i]] != mod)
                dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
        }
    }

    ll ans = 0;

    for (int i = 0; i <= 200000; i++) {
        if(dp[i] <= w) ans = i;
    }

    cout << ans << '\n';

    return 0;
}

/*
3
10 40 70
20 50 80
30 60 90

10  40  70
90  120 120
150 180 210
*/


















Measured memory_bytes: 10496
let list_of_str s = let rec f i = if i >= String.length s then [] else s.[i] :: f (i+1) in f 0
let rec for_iter a b f = if a > b then [] else let x = f a in x :: for_iter (a+1) b f
let () =
  let s = Scanf.scanf "%s" list_of_str in
  for_iter 97 (97+25) (fun i ->
    let c = char_of_int i in
    List.filter ((=) c) s |> List.length |> (fun x -> x mod 2))
  |> List.fold_left (+) 0
  |> (fun x -> Printf.printf "%d\n" (x / 2))


Measured memory_bytes: 2472
n, m, k = gets.split.map(&:to_i)
a_books = gets.split.map(&:to_i)
b_books = gets.split.map(&:to_i)

a_times = (0...n).each_with_object([0]) { |num, result|
  result << result.last + a_books[num]
}

b_times = (0...m).each_with_object([0]) { |num, result|
  result << result.last + b_books[num]
}

sum_counts = [0]
(0..n).each_with_object(sum_counts) { |a_count, result|
  rest_time = k - a_times[a_count]
  next if rest_time < 0

  over = b_times.bsearch_index { |b_time| b_time > rest_time } || m + 1
  result << a_count + over - 1
}

puts sum_counts.max


Measured memory_bytes: 45196