akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	int N;
	cin >> N;
	int A[N+1];
	bool visited[N+1];
	for(int i=1;i<=N;i++){
		cin >> A[i];
		visited[i]=false;
	}

	int cnt=0;
	for(int a=1;!visited[a];a=A[a]){
		visited[a]=true;
		if(a==2){
			cout << cnt << endl;
			return 0;
		}
		cnt++;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 768
s = input()
for i in range(2**3):
    f = s[0]
    for j in range(3):
        if i>>j & 1:
            f += '+'
        else:
            f += '-'
        f += s[j+1]
    if eval(f) == 7:
        print(f+'=7')
        exit()


Measured memory_bytes: 2940
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

typedef array<int, 3> point;

int n;
point a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<2*n; i++) {
		scanf("%d %d", &a[i][0], &a[i][1]);
		a[i][2] = i<n;
	}
	return 1;
}

void init() {
}

long solve() {
	long r = 0;
	n*=2;
	sort(a, a+n);
	multiset<int> s;
	for (int i=0; i<n; i++) {
		if (a[i][2]) { //red
			s.insert(a[i][1]);
		}
		else { //blue
			int y = a[i][1];
			auto p = s.lower_bound(y);
			if (p != s.begin()) {
				--p;
				s.erase(p);
				r++;
			}
		}
	}
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    unsigned long H,W;
    cin >> H >> W;
    unsigned long out = 0;
    if(H == 1 || W == 1){
        out = 1;
    }else{
        out = H*W/2;
        if(H*W % 2 == 1) out++;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void cut(int k, vector< int > &v){
	int n = v.size();
	vector< int > temp(k);
	REP(i, k) temp[i] = v[i];
	REP(i, n - k) v[i] = v[i + k];
	REP(i, k) v[n - k + i] = temp[i];
}

void riffle(vector< int > &v){
	int n = v.size();
	vector< int > temp(v);
	
	REP(i, n){
		v[i] = (i%2 ? temp[i/2 + n/2] : temp[i/2]);
	}
}

int main(){
	
	int n, m, k;
	vector< int > card;
	
	cin >> n >> m;
	
	card.RS(2*n);
	REP(i, 2*n) card[i] = i + 1;
	
	REP(i, m){
		cin >> k;
		if(k > 0){
			cut(k, card);
		}else{
			riffle(card);
		}		
	}
	
	REP(i, 2*n){
		cout << card[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
struct tree{
  vector<vector<int>> G,son,ancestor;
  vector<int> depth,parent;
  queue<int> que;
  int root=-1;
  bool made_lca=false;

  tree(int n):G(n),son(n),parent(n,-1),depth(n,-1),ancestor(n){
    for(int i=0;i<n;i++)ancestor[i].resize(30);
  }

  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  inline void reset_root(){
    root=-1;
    fill(depth.begin(),depth.end(),-1);
    fill(parent.begin(),parent.end(),-1);
    for(auto &p:ancestor)for(int &q:p)q=-1;
    for(auto &p:son)p.resize(0);
    made_lca=false;
  }

  void have_root(int r){
    reset_root();
    root=r;
    que.push(r);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:G[p]){
        if(parent[p]==q)continue;
        son[p].push_back(q);
        parent[q]=p;
        que.push(q);
      }
    }
  }

  void set_depth(){
    assert(~root);
    depth[root]=0;
    que.push(root);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:son[p]){
        depth[q]=depth[p]+1;
        que.push(q);
      }
    }
  }

  inline void make_lca(){
    assert(~root);
    if(depth[root]<0)set_depth();
    for(int i=0;i<G.size();i++)ancestor[i][0]=parent[i];
    for(int j=1;j<30;j++)
      for(int i=0;i<G.size();i++)
        if(~ancestor[i][j-1])
          ancestor[i][j]=ancestor[ancestor[i][j-1]][j-1];
    made_lca=1;
  }

  int lca(int u,int v){
    if(!made_lca)make_lca();
    if(depth[u]>depth[v])swap(u,v);
    int diff=depth[v]-depth[u],cnt=0;
    while(diff){
      if(diff&1)v=ancestor[v][cnt];
      cnt++;
      diff>>=1;
    }
    if(u==v)return u;
    for(int k=28;k>=0;k--)
      if(ancestor[u][k]!=ancestor[v][k])
        u=ancestor[u][k],v=ancestor[v][k];
    return ancestor[u][0];
  }
};
int n,odd,now[4],ans[223456],s=-1;
int f(int a,int b,int c){
  int v[3]={a,b,c};
  for(int p:v)if(now[p]*3+p<=n)return now[p]++*3+p;
  return -1;
}

signed main(){
  cin>>n;
  tree t(n);
  for(int i=1;i<n;i++){
    int u,v;cin>>u>>v;u--;v--;
    t.add_edge(u,v);
  }
  t.have_root(0);
  t.set_depth();
  for(int i=0;i<n;i++)odd+=t.depth[i]&1;
  if(odd<=n/3)s=1;
  if(n-odd<=n/3)s=0;
  for(int i=0;i<n;i++){
    if((t.depth[i]&1)==s)ans[i]=f(3,2,1);
    else if(~s)ans[i]=f(1,2,3);
    else ans[i]=f(1+(t.depth[i]&1),3,2-(t.depth[i]&1));
  }
  for(int i=0;i<n;i++)cout<<ans[i]<<" ";cout<<endl;
}


Measured memory_bytes: 52992
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    int left = d[n/2 -1];
    int right = d[n/2];
    if(left == right)
        cout << 0 << endl;
    else
        cout << right - left << endl;
}



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

string s;

bool p(string k){
	for(int i = 0; i < k.size(); i++){
		if(k[i] != k[k.size()-1-i]) return false;
	}
	return true;
}
bool bos = true;
int main(){
	cin >> s;
	bos *= p(s);
	int n = s.size(); 
	string s1 = "";
	for(int i = 0; i < (n-1)/2; i++){
		s1+=s[i];
	}
	bos *= p(s1);
	s1 = "";
	for(int i = (n+3)/2-1; i < n; i++){
		s1 += s[i];
	}
	bos *= p(s1);
	if(bos){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
void chmin(int*,int);
void chmax(int*,int);
int main(void)
{
    int n,k;
    int h[100000];
    int dp[100001];

    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    for(int i=0;i<=n;i++)dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j-i<=k&&j<n;j++){
            /*if(dp[j]>dp[i]+abs(h[j]-h[i])){
                dp[j]=dp[i]+abs(h[j]-h[i]);
            }*/
            chmin(&dp[j],dp[i]+abs(h[j]-h[i]));
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}
void chmin(int* x,int y){if(*x>y)*x=y;}
void chmax(int* x,int y){if(*x<y)*x=y;}

Measured memory_bytes: 896
import sys
import itertools
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N = int(input())
c = [inputs() for _ in range(N-1)]
ans = [0]*(N)
start = [[0]*N for _ in range(N)]
for i in range(N-1):
    start[i][i] = c[i][1]
    for j in range(i,N-1):
        if ans[i]<c[j][1]:
            start[i][j] = c[j][1]
            ans[i] = c[j][1]+c[j][0]
        else:
            ttim=0
            if ans[i]%c[j][2]!=0:
                ttim=c[j][2]-(ans[i])%c[j][2]
            start[i][j] = ttim+ans[i]
            ans[i] = ttim+ans[i]+c[j][0]
print(*ans)



Measured memory_bytes: 42096
#include <iostream>
#include <cmath>
 
 
using namespace std;
 
int main(void) {
 
    int n;
    cin >> n;
 
    long min = 1000000;
    long max = -1000000;
    long sum = 0;
 
    int a;
    for(int i=0;i<n;i++) {
        cin >> a;
        sum += a;
        if(min > a)  min = a;
        if(max < a)  max = a;
    }
 
    cout << min << " " << max << " " << sum << endl;
 
 
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define maxn 100010
#define M 1000000007
using namespace std;
long long a[maxn],t[maxn],p[maxn];
long long pwr(long long a,long long n)
{
    if(n==0)return 1;
    long long ans=pwr(a,n/2);
    ans=(ans*ans)%M;
    if(n&1)return (ans*a)%M;
    return ans;
}
long long C(int n,int m)
{
    if(n<m)return 0;
    return (((a[n]*pwr(a[m],M-2))%M)*pwr(a[n-m],M-2))%M;
}
int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<=n;i++)cin>>t[i];
    int x,y;
    for(int i=0;i<=n;i++)
    {
        if(p[t[i]])
        {
            x=p[t[i]];
            y=i+1;
            break;
        }
        p[t[i]]=i+1;
    }
    a[0]=1;
    for(int i=1;i<n+8;i++)a[i]=(a[i-1]*i)%M;
    cout<<n<<endl;
    for(int i=2;i<=n;i++)
    {
        long long ans=C(n+1,i)-C(x-1+n+1-y,i-1);
        ans%=M;
        ans=(ans+M)%M;
        cout<<ans<<endl;
    }
    cout<<1<<endl;
return 0;
}
/*
32
524
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1
*/


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

const int MAX_A = 300005;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  segtree<int, op, e> dp(MAX_A);
  int ans = 0;
  rep(i, n) {
    int x = a[i];
    int now = dp.prod(max(0, x-k), min(MAX_A, x+k+1)) + 1;
    dp.set(x, now);
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9636
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll A,P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long long n,i,c=0,m,x,y;
	scanf("%lld%lld",&n,&m);
	x=m,y=m,c+=m;
	for(i=0;i<n-1;i++){
		scanf("%lld",&m);
		if(x>m)x=m;
		if(y<m)y=m;
		c+=m;
	}
	printf("%lld %lld %lld\n",x,y,c);
	return 0;
}


Measured memory_bytes: 2024
def main():
    N = int(input())
    D = [int(n) for n in input().split()]
    M = int(input())
    T = [int(n) for n in input().split()]
    # print(N)
    # print(D)
    # print(M)
    # print(T)
    d_dict = {}
    t_dict = {}
    for i in D:
        d_dict[i] = d_dict.get(i, 0) + 1
    for i in T:
        t_dict[i] = t_dict.get(i, 0) + 1
    # print(d_dict)
    # print(t_dict)

    ok = True
    for k in t_dict.keys():
        if d_dict.get(k, 0) < t_dict[k]:
            ok = False
            break

    if ok:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 56544
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int K,N;
  cin>>K>>N;
  vector<int>A(N);
  for(int i=0;i<=N-1;i++){
  
    cin>>A[i];
  }
  int max=-1;
  for(int i=0;i<=N-2;i++){
  
    if(max<A[i+1]-A[i])max=A[i+1]-A[i];
  }
  if(max<K-A[N-1]+A[0])max=K-A[N-1]+A[0];
  if(max<0)max=0;
  cout<<K-max;
  return 0;
}

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

int main(){
  long long x,money=100;
  cin>>x;
  int cnt=0;
  
  while(true){
    money+=money/100;
    cnt++;
    if(money>=x)break;
  }
  cout<<cnt<<endl;
  
  return 0;
}

Measured memory_bytes: 3596
from collections import deque

N, M, Q = map(int, input().split(" "))
que = deque()
for i in range(1, M + 1):
    que.append([i])

while True:
    now = que.popleft()
    if len(now) == N:
        que.append(now)
        break

    last = now[-1] if len(now) > 0 else 1
    for i in range(last, M + 1):
        que.append(now + [i])

cond = []
for _ in range(Q):
    cond.append(tuple(map(int, input().split(" "))))

ans = 0
for seq in que:
    score = 0
    for i in range(Q):
        a, b, c, d = cond[i]
        if seq[b - 1] - seq[a - 1] == c:
            score += d
    ans = max(ans, score)
print(ans)

Measured memory_bytes: 102864
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    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:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [i32; n],
  }
  let mut approve = true;
  for &x in &a {
    if x % 2 != 0 {
      continue;
    }
    if x % 3 != 0 && x % 5 != 0 {
      approve = false;
      break;
    }
  }

  puts!("{}\n", if approve { "APPROVED" } else { "DENIED" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n;cin>>n;
  vi v(n);
  rep(i,n){
    int a;cin>>a;
    v[a-1]=i+1;
  }
  rep(i,n){
    if(i)cout<<' ';
    cout<<v[i];
  }
  cout<<endl;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main(){
  
string st;
  cin>>st;
  int ans=0;
  for(int i=0; i<st.length(); i++){
  
  if(st[i]=='+'){
  ans++;
  }
    else{
    ans--;}
  
  }
  cout<<ans;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();	
	while(v<'0'||v>'9'){
	v=getchar();
	}	
	while(v>='0'&&v<='9'){		
	t=(t<<3)+(t<<1)+(v^48);		
	v=getchar();	}
	return t;
}
double a,b,c,d;
int main(){
a=read();
for(double i=1;i<=a;++i){
	if(i*1.08>=a&&i*1.08<a+1){
		cout<<i<<endl;return 0;
	}
}
puts(":(");
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define INF 2147483647
 
using namespace std;

int pos(long long x, long long n)
{
	long long res;
	if (n == 0) return (1);
	
	res = (unsigned long long)pos(x * x % 1000000007, n / 2);
	if (n % 2 == 1) res = res * x % 1000000007;
 
	return (res);
}

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

	cout << pos(m, n) << endl;

	return (0);
}

Measured memory_bytes: 1164
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
# import functools
# import itertools
# import math
N,C=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(N)]
stc=sorted(stc,key=lambda x:x[0])
#print(stc)
rokugaki=[]
for s,t,c in stc:

    a=[i for i in range(len(rokugaki)) if rokugaki[i][1]==c]
    if not a:
        a=[i for i in range(len(rokugaki)) if rokugaki[i][0]<s]
    if a:
        rokugaki[a[0]]=[t,c]

    else:
        rokugaki.append([t,c])
    #print(rokugaki)

print(len(rokugaki))


Measured memory_bytes: 67928
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve()
{
    long long sum = 0;
    long long n, m;
    cin >> n >> m;
    while(m--){
        long long x;
        cin >> x;
        sum+=x;
    }
    long long k = -1;
    cout << max(k, n - sum);
    return;  
}

int main() 
{
    FIO;
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename TYPE> TYPE gcd(TYPE a, TYPE b){return (a % b)? gcd(b, a % b) : b;}
template<typename TYPE> TYPE lcm(TYPE a, TYPE b){return a * b / gcd(a, b);}

void solve_131C(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll div = lcm(c, d);
    ll nonA = (b / c - (a-1) / c), nonB = (b/d - (a-1)/d);
    ll uni = b / div - (a-1) / div;

    cout << (b-a) - (nonA + nonB - uni) +1 << endl;
}

int main(void){
    solve_131C();
    //cout << solve_145D() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//用来求两数之差
double difference(double a,double b)
{
	if(a>b)
		return a-b;
	return b-a;
}
int main()
{
	
	double x1,y1,x2,y2,edge3,edge1,edge2,n,m;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	edge1=difference(y1,y2);
	edge2=difference(x1,x2);
	n=edge1*edge1;
	m=edge2*edge2;
	edge3=sqrt(n+m);
	printf("%f",edge3);
	return 0;
}


Measured memory_bytes: 2120
#include<stdio.h>
int main(){
  int i=0;
  char s[3];
  while(1){
    scanf("%c",&s[0]);
    if(s[0]=='\n')break;
    if(i==0){
      printf("%c",s[0]);
      i=1;
    }else
      i=0;
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
s = gets.chomp

h = {}
s.chars.each do |x|
  if h.key?(x)
    h[x] += 1
  else
    h[x] = 1
  end
end
if h.keys.length == 2 && h.values.all? {|x| x == 2 }
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String args[]){
		//System.out.println("Please input grades below");
		//宣言
		sc = new Scanner(System.in);
		int m[]= new int[500];
		int f[]= new int[500];
		int r[]= new int[500];
		int s[]= new int[500];
		int i=1;
		//入力
		for(;;) {
			m[i]=sc.nextInt();
			f[i]=sc.nextInt();
			r[i]=sc.nextInt();
			s[i]=m[i]+f[i];
			if(m[i]==-1 &&f[i]==-1 &&r[i]==-1) {
				break;
			}
			i++;
		}
		i=1;
		
		//出力
		for(;;) {
			if(m[i]==-1 &&f[i]==-1 &&r[i]==-1) {
				break;
			}
			//System.out.println(s[i]);
			if(m[i]==-1 ||f[i]==-1) {
				System.out.println("F");
			}else if(s[i]>=80) {
				System.out.println("A");
			}else if(s[i]>=65 && s[i]<80) {
				System.out.println("B");
			}else if(s[i]>=50 && s[i]<65) {
				System.out.println("C");
			}else if(s[i]>=30 && s[i]<50) {
				if(r[i]>=50) {
					System.out.println("C");
				}else {
					System.out.println("D");
				}
			}else {System.out.println("F");
			}
			i++;
		}
	}
}


Measured memory_bytes: 26188
#include <cstdio>
#include <algorithm>
int ans = 0;
int GCD(int a, int b){
	if(b==0)return a;
	ans++;
	return GCD(b, a%b);
}

int main(){
	int x, y;
	while(scanf("%d %d",&x, &y), x+y){
		ans = 0;
		if(x < y)std::swap(x,y);
		int gcd = GCD(x, y);
		printf("%d %d\n", gcd, ans);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int n;
int dp[100000][3];

int helper(int a[][3],int i,int j)
{
	if(i<0)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(j==0)
	return dp[i][j] = max(a[i][j]+helper(a,i-1,j+1),a[i][j]+helper(a,i-1,j+2) );
    else if(j==1)
	return dp[i][j] = max(a[i][j]+helper(a,i-1,j+1),a[i][j]+helper(a,i-1,j-1) );
    else if(j==2)
	return dp[i][j] = max(a[i][j]+helper(a,i-1,j-1),a[i][j]+helper(a,i-1,j-2) );
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  
  cin>>n;
  int a[n][3];

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

  for (int i = 0; i < n; ++i)
  {
  	for(int j=0;j<3;++j)
  		dp[i][j]=-1;
  }
  //  int ans=-1e9;
  // for(int j=0;j<3;j++)
  // {
  //    ans = max(ans,helper(a,n-1,j));
  // }
  int aa=helper(a,n-1,0);
  int b=helper(a,n-1,1);
  int c=helper(a,n-1,2);
  cout<<max(max(aa,b),c);
  return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k; ll num;
    cin >> n >> k;
    vector<ll> ap, an, a;
    for(int i=0;i<n;++i) {
        cin >> num;
        a.push_back(abs(num));
        if(num > 0) ap.push_back(num);
        else if(num < 0) an.push_back(-num);
    }

    // 答えが 0 にしかならない
    if(ap.size() == 0 && an.size() == 0) {
        cout << 0 << endl;
        return 0;
    }

    // 答えを正の数にできる？
    ll ans = 1LL;
    sort(ap.rbegin(), ap.rend());
    sort(an.rbegin(), an.rend());
    int pi = 0, ni = 0, kk = 0;
    while(kk < k-1 && (pi < int(ap.size())-1 || ni < int(an.size())-1)) {
        if(ni >= int(an.size())-1 || (pi < int(ap.size())-1 && ap[pi+1] * ap[pi] > an[ni+1] * an[ni])) {
            ans *= ap[pi];
            ++pi;
            ++kk;
        } else {
            ans *= (an[ni+1] * an[ni]) % MOD;
            ni += 2;
            kk += 2;
        }
        ans %= MOD;
    }
    while(kk < k && pi < int(ap.size())) {
        ans *= ap[pi++];
        ans %= MOD;
        ++kk;
    }
    if(kk == k) {
        cout << ans << endl;
        return 0;
    }

    // 答えを正にできないため，できるだけ絶対値を抑える
    sort(a.begin(), a.end());
    ans = 1LL;
    for(int i=0;i<k;++i) {
        ans *= a[i];
        ans %= MOD;
    }
    cout << (MOD-ans) % MOD << endl;
}


Measured memory_bytes: 7480
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>


using namespace std;
typedef long long ll;

int main(){
	int n, m, i, j;
	int a[111], b[111];
	char t[111];
	ll ans, sum;
	cin >> t;
	n = strlen(t);
	if(n == 2)
	{
		for(i = 0; i < n; i++)
			cout << t[i];
		printf("\n");
	}
	if(n == 3){
		for(i = n - 1; i >= 0; i--)
			cout << t[i];
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  ss <- words <$> getLine :: IO [String]
  let is = map read ss :: [Int]
  if test is then
      putStr "Yes"
  else
      putStr "No"
      where test = cmpsm . concat . map spl . rot 
  
  
cmpsm :: [([Int], [Int])] -> Bool
cmpsm = foldr (\t b -> ((sum $ fst t) == (sum $ snd t)) || b) False

spl :: [Int] -> [([Int], [Int])]
spl []  = []
spl [_] = []
spl (x:xs)  = ([x], xs) : [(x:ls,rs) | (ls,rs) <- spl xs]

rot :: [Int] -> [[Int]]
rot xs = [(drop i xs) ++ (take i xs) | i <- [1..length xs]]


Measured memory_bytes: 508
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = input[0][0];

  return `ABC${N}`;
};

console.log(main(read()));

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

int X;

int main() {
	cin>>X;
	
	if((X>=400) && (X<=599)){
		cout<<"8"<<endl;
	} else if((X>=600) && (X<=799)){
		cout<<"7"<<endl;
	} else if((X>=800) && (X<=999)){
		cout<<"6"<<endl;
	} else if((X>=1000) && (X<=1199)){
		cout<<"5"<<endl;
	} else if ((X>=1200) && (X<=1399)){
		cout<<"4"<<endl;
	} else if((X>=1400) && (X<=1599)){
		cout<<"3"<<endl;
	} else if((X>=1600) && (X<=1799)){
		cout<<"2"<<endl;
	} else if((X>=1800) && (X<=1999)){
		cout<<"1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3628
# ほぼ写経
from math import gcd
from collections import defaultdict
mod = 10**9+7
n = int(input())
mp = defaultdict(lambda: [0, 0])
zero_zero = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    rot_cnt = 0
    while not (a > 0 and b >= 0):
        a, b = -b, a
        # ベクトルの成分が(正,正)となるまで90度回転、奇数回の時は元のベクトルと直行することになるのでrot_cntで記録
        # 今回の問題においては内積0を計算すればいいので逆ベクトルは考慮しなくてよい
        rot_cnt += 1
    mp[(a, b)][rot_cnt % 2] += 1
ans = 1
for s, t in mp.values():
    now = (pow(2, s, mod) + pow(2, t, mod) - 1) % mod
    ans = (ans * now) % mod
ans = (ans - 1 + zero_zero) % mod
print(ans)


Measured memory_bytes: 60912
// Aizu Vol-1 0109: Smart Calculator
// 2017.8.5

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX 200
#define INF   1000000010
#define LEFT (INF+1)
#define RIGHT (INF+2)
#define PLUS (INF+3)
#define MINUS (INF+4)
#define MUL (INF+5)
#define DIV (INF+6)

char *gets(char *);
char buf[200], *p;
int S[MAX + 3], top;
int Q[MAX + 3], end;

int getInt(void)
{
	int n = 0;
//	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int token(char c)
{
	if (c == '+') return PLUS;
	if (c == '-') return MINUS;
	if (c == '*') return MUL;
	return DIV;
}

int rank(int op)
{
	if (op == PLUS || op == MINUS) return 2;
	if (op == MUL || op == DIV) return 3;
	return 1;
}

int main()
{
	int i, f, k, d1, d2;
	int cno, cmax;

	gets(p = buf); cmax = getInt();
	for (cno = 0; cno < cmax; cno++) {
		gets(p = buf), f = 1, top = 0, end = 0;
		while (1) {
			while (isspace(*p)) p++;
			if (!*p || *p == '=') {
				while (top) Q[end++] = S[--top];
				break;
			}
			if (*p == '-' && f && isdigit(*(p + 1))) {
				p++;
				Q[end++] = -getInt();
				f = 0;
				continue;
			}
			f = 0;
			if (isdigit(*p)) Q[end++] = getInt();
			else if (*p == ')') {
				while (S[top - 1] != LEFT) Q[end++] = S[--top];
				top--, p++;
			}
			else if (*p == '(') S[top++] = LEFT, p++, f = 1;
			else {
				k = token(*p++);
				while (top) {
					if (rank(k) <= rank(S[top - 1])) Q[end++] = S[--top];
					else break;
				}
				S[top++] = k;
			}
		}
#if 0
		for (i = 0; i < end; i++) printf("%d ", Q[i]);
		printf("\n");
#endif
		for (top = i = 0; i < end; i++) {
			if ((k = Q[i]) > INF) {
				d1 = S[--top], d2 = S[--top];
				if (k == PLUS) d2 += d1;
				else if (k == MINUS) d2 -= d1;
				else if (k == MUL) d2 *= d1;
				else d2 /= d1;
				S[top++] = d2;
			} else S[top++] = k;
		}
		printf("%d\n", S[--top]);
	}
	return 0;
}

Measured memory_bytes: 524
N = int(input())

songs = []
result = 0

for i in range(N):
    songs.append(input().split())

X = input()
point = len(songs)

for j in range(N):
    if songs[j][0] == X:
        point = j+1
        break

for i in range(point, N):
    result += int(songs[i][1])


print(result)


Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>

#define maxn 100005

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n;
int a[maxn];
int ans;

int main()
{
    n=getint();
	for(int i=1;i<=n;i++)a[i]=getint();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)for(int j=i+1;j<n;j++)
	{
		int tmp=a[i]+a[j];
		int l=j,r=n;
		while(l<r)
		{
			int mid=(l+r)>>1;if(l==mid)mid++;
			if(a[mid]<tmp)l=mid;
			else r=mid-1;
		}
		ans=ans+(l-j);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
using pii = pair<int, int>;
using vec = vector<int>;
using pq = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define mp(x, y) make_pair((x), (y))
#define space " "

constexpr lint MOD = 1e9 + 7;
int A, B, C, F, H, I, J, K, L, M, N, P, Q, S, T, U, W, X, Y;
// lint A, B, F, H, I, J, K, L, M, N, P, Q, S, T, U, W, X, Y;
// int ans = 0;
// string ans;
vector<set<int>> graph;
vec points;
vector<bool> done;

void aggregate(int p, int c) {
	if (done[c]) return;
	done[c] = true;
	if (c != 0) points[c] += points[p];
	for (auto n : graph[c]) aggregate(c, n);
}

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

	cin >> N >> Q;
	graph.resize(N);
	points.assign(N, 0);
    rep(i, N - 1) {
        cin >> F >> S;
		F--; S--;
		graph[F].insert(S);
		graph[S].insert(F);
    }
	rep(i, Q) {
		cin >> P >> X;
		P--;
		points[P] += X;
	}

	done.assign(N, false);
	aggregate(0, 0);

	rep(i, N) {
		cout << points[i] << space;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 37632
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

const int maxn = 1e5 + 10;
pair<ll, ll> p[maxn];
ll par[maxn];
ll s[maxn];
ll sum;
ll ans[maxn];
ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    for (int i = 1; i <= n; i++) {
        par[i] = i;
        s[i] = 1;
    }
    for (int i = 0; i < m; i++) {
        scanf("%lld%lld", &p[i].first, &p[i].second);
    }
    sum = 1LL * n * (n - 1) / 2;
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = sum;
        int x = find(p[i].first), y = find(p[i].second);
        if (x != y) {
            par[y] = x;
            sum -= s[x] * s[y];
            s[x] += s[y];
        }
    }
    for (int i = 0; i < m; i++) printf("%lld\n", ans[i]); 
    return 0;
}

Measured memory_bytes: 5120
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;



int main(){
ll A,B;
cin>>A>>B;
if(((A%2+B%2)%2)!=0){
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

cout<<(A+B)/2<<endl;


return 0;
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
   long long N;
   cin >> N;
   string ans;
   while(N != 0){
       int r = N % (-2);
       if(r == -1)r = 1;
       N = (N-r) / (-2);
    ans.push_back((char)('0'+ r));
   }
reverse(ans.begin(),ans.end());
if(ans == "")ans = "0";
cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

class Combination{
    long long powmod(long long a, long long p){
        long long ans = 1LL;
        long long mul = a;
        while(p>0){
            if((p&1)==1) {
                ans = (ans * mul) % MOD;
            }
            mul=(mul*mul)%MOD;
            p>>=1;
        }
        return ans;
    }

public:
    int N;
    long long mod;
    vector<long long> fact;
    vector<long long> revfact;

    Combination(int n, long long m) : N(n), mod(m), fact(n+1), revfact(n+1){
        fact[0]=1;
        for(int i=1; i<=N; i++){
            fact[i]=fact[i-1]*i;
            fact[i]%=mod;
        }

        revfact[N] = powmod(fact[N], mod-2);
        for(int i=N-1; i>=0; i--){
            revfact[i]=revfact[i+1]*(i+1)%mod;
        }
    }

    long long getCombination(int a, int b){
        if(a<0 || b<0) return 0;
        if(b>a)return 0;
        return fact[a]*revfact[b]%mod*revfact[a-b]%mod;
    }
};

int main() {
    int N, K; cin >> N >> K;
    Combination comb=Combination(N+2, MOD);

    for(int i=1; i<=K; i++){
        lli ans=0LL;
        lli get_a=comb.getCombination(N-K+1, i),
            get_b=comb.getCombination(K-1, i-1);

        ans=(get_a*get_b)%MOD;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int n,k,a[100000],dp[100000];
  memset(dp,1000000,sizeof(dp));
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i+=1){
    scanf("%d",&a[i]);
  }
  //printf("%d",dp[0]);
  dp[0]=0;
  for(int i=1;i<n;i+=1){
      for(int j=1;j<min(k+1,n);j+=1){
          if((i-j)<0){
              break;
          }
          dp[i]=min(dp[i],(abs(a[i]-a[i-j])+dp[i-j]));
      }
  }
  printf("%d",dp[n-1]);
}

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

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		vector<int> v(n);
		for (int i = 0; i < n; i++)cin >> v[i];
		int d[5010];
		for (int i = 0; i < 5001; i++)d[i] = -200000;
		d[0] = v[0];
		for (int i = 1; i < n; i++)
		{
			d[i] = v[i];
			if (d[i] + d[i - 1] > d[i])
			{
				d[i] += d[i - 1];
			}
		}
		int ans = -2000000;
		for (int i = 0; i < n; i++)ans = max(ans, d[i]);
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 1224
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
alias Queue=DList;auto enq(T)(ref Queue!T q,T e){q.insertBack(e);}T deq(T)(ref Queue!T q){T e=q.front;q.removeFront;return e;} 
alias Stack=SList;auto push(T)(ref Stack!T s,T e){s.insert(e);}T pop(T)(ref Stack!T s){T e=s.front;s.removeFront;return e;} 
struct UnionFind(T){T[T]u;ulong[T] rank;@property{bool inc(T e){return e in u;}auto size(){return u.keys.length;}auto dup(){T[] child=u.keys;T[] parent=u.values;auto res=UnionFind!T(child);child.each!(e=>res.add(e));size.iota.each!(i=>res.unite(child[i],parent[i]));return res;}}this(T e){e.add;}this(T[] es){es.each!(e=>e.add);}auto add(T a,T b=a){assert(b.inc);u[a]=a;rank[a];if(a!=b)unite(a,b);}auto find(T e){if(u[e]==e)return e;return u[e]=find(u[e]);}auto same(T a,T b){return a.find==b.find;}auto unite(T a,T b){a=a.find;b=b.find;if(a==b)return;if(rank[a]<rank[b])u[a]=b;else{u[b]=a;if(rank[a]==rank[b])rank[a]++;}}}
struct PriorityQueue(T,alias less="a<b"){BinaryHeap!(T[],less) heap;@property{bool empty(){return heap.empty;}auto length(){return heap.length;}auto dup(){return PriorityQueue!(T,less)(array);}T[] array(){T[] res;auto tp=heap.dup;foreach(i;0..length){res~=tp.front;tp.removeFront;}return res;}void push(T e){heap.insert(e);}void push(T[] es){es.each!(e=>heap.insert(e));}}T look(){return heap.front;}T pop(){T tp=look;heap.removeFront;return tp;}this(T e){ heap=heapify!(less,T[])([e]);}   this(T[] e){ heap=heapify!(less,T[])(e);}}
//END OF TEMPLATE

void main(){
    long a,b,c,d;
    scan(a,b,c,d);
    while(true){
        c-=b;
        if(c<=0){
            "Yes".writeln;
            break;
        }
        a-=d;
        if(a<=0){
            "No".writeln;
            break;
        }
    }   
}


Measured memory_bytes: 3660
def main():
    from itertools import combinations_with_replacement
    import sys
    input = sys.stdin.buffer.readline
    N, M, Q = (int(i) for i in input().split())
    T = [[int(i) for i in input().split()] for j in range(Q)]
    ans = 0
    for C in combinations_with_replacement(range(1, M+1), N):
        A = sorted(C)
        cur = 0
        for a, b, c, d in T:
            if A[b-1] - A[a-1] == c:
                cur += d
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73668
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 105
typedef complex<double> P;

double eps=1e-6;

bool eq(double a,double b){
  
  return (-eps < a-b && a-b < eps);
}

struct S{
  P s,t;
};

P intersect(P a,P b,P c,P d){
  a-=d,b-=d,c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

P intersect(S a,S b){
  return intersect(a.s,a.t,b.s,b.t);
}

bool isParallel(S a,S b){
  P ap=a.t-a.s;
  P bp=b.t-b.s;
  return eq( 0 , imag( ap/bp ) );
}

double distance(S a,P p){
  return imag( (p-a.s)*conj(a.t-a.s) )/abs(a.t-a.s);
}

int n;
S t[MAX_N];

vector<S> calc(S a,S b){
  vector<S> res;

  P ap=a.t-a.s;
  P bp=b.t-b.s;
  
  if( isParallel(a,b) ){
    P o=(a.s+b.s)*0.5;
    res.push_back( (S){o , o+ap } );
    return res;
  }
  
  P base=intersect(a,b);

  ap/=abs(ap);
  bp/=abs(bp);
  res.push_back( (S){ base,base+ap+bp  });
  res.push_back( (S){ base,base+ap-bp  });
  return res;
}

void solve(){
  if(n<=2){
    cout<<"Many"<<endl;
    return;
  }
  vector< P > vec;
  
  S a=t[0],b=t[1],c=t[2];
  vector< S > va=calc(a,b),vb=calc(b,c),vc=calc(c,a);
  for(int i=0;i<(int)va.size();i++){
    for(int j=0;j<(int)vb.size();j++){
      for(int k=0;k<(int)vc.size();k++){
        S ab=va[i];
        S bc=vb[j];
        S ca=vc[k];
        if( isParallel(ab,bc) || isParallel(bc,ca) || isParallel(ca,ab) ){
          continue;
        }


        P target=intersect(ab,bc);
        //        P q0=intersect(bc,ca);
        //        P q1=intersect(ca,ab);
        //        if( abs(target-q0) > eps )continue;
        //        if( abs(target-q1) > eps )continue;
        bool flg=true;
        double dist= abs( distance( t[0] , target) );
        for(int id=0;id<n;id++){
          if( !eq( dist, abs(distance( t[id] , target) ) ) )
            flg=false;
        }

        if(flg)vec.push_back(target);
        
      }
    }
  }
  vector< P > ans;
  for(int i=0;i<(int)vec.size();i++){
    bool flg=true;
    for(int j=0;j<(int)ans.size();j++){
      if( abs(vec[i]-ans[j]) < eps )flg=false;
    }
    if(flg)ans.push_back(vec[i]);
  }

  
  if(ans.size()==0){
    cout<<"None"<<endl;
  }else if(ans.size()==1){
    printf("%.10f %.10f\n",real(ans[0]),imag(ans[0]));
  }else{
    cout<<"Many"<<endl;
  }
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      double x,y;
      cin>>x>>y;
      t[i].s=P(x,y);
      cin>>x>>y;
      t[i].t=P(x,y);


      
    }
    solve();
  }
  return 0;
}

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

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    void run() {
        int S = readInt();
        int h = S / 3600;
        int m = (S % 3600) / 60;
        int s = (S % 3600) % 60;
        sysout.printf("%d:%d:%d\n", h, m, s);
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
}

Measured memory_bytes: 17120
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1), B(N);
  copy_n(istream_iterator<int>(cin), N + 1, A.begin());
  copy_n(istream_iterator<int>(cin), N, B.begin());
  int64_t res = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 2; ++j) {
      if (B[i] <= A[i + j]) {
        res += B[i];
        A[i + j] -= B[i];
        break;
      } else {
        res += A[i + j];
        B[i] -= A[i + j];
        A[i + j] = 0;
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

int main() {
    int i,len;
    string ch;

    cin >> ch;

    len = ch.length();
 
    for(i = 0;i < len / 2;i++){
        char box = ch[i];
        ch[i] = ch[len - i - 1];
        ch[len - i - 1] = box;
    }

    cout << ch << endl;

    return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
set<string> s;
int main(){
	ios::sync_with_stdio(0);
	string st;
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>st,s.insert(st);
	cout<<s.size();
	return 0;
}

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

int main() {
    int a, b, c = 0;
    std::vector<int> cost;
    std::cin >> a >> b >> c;

    cost.push_back(std::abs(b - a) + std::abs(c - b));
    cost.push_back(std::abs(c - a) + std::abs(c - b));
    cost.push_back(std::abs(a - b) + std::abs(c - a));
    cost.push_back(std::abs(c - b) + std::abs(c - a));
    cost.push_back(std::abs(b - c) + std::abs(a - b));
    cost.push_back(std::abs(a - c) + std::abs(a - b));
    std::sort(cost.begin(),cost.end());
    std::cout << cost[0] << std::endl;
    return 0;
}

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

using namespace std;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> C(n);
    vector<vector<int>> A(n, vector<int>(m));

    for (int i = 0; i < n; i++){
        cin >> C[i];
        copy_n(istream_iterator<int>(cin), m, A[i].begin());
    }

    const constexpr int INF = 1e9;
    int ans = INF;
    for (int bits = 0; bits < (1 << n); bits++){
        vector<int> B(m);
        int res = 0;
        for (int i = 0; i < n; i++){
            if (bits >> i & 1){
                res += C[i];
                for (int j = 0; j < m; j++){
                    B[j] += A[i][j];
                }
            }
        }

        if (all_of(B.begin(), B.end(), [&](auto &b){return b >= x;}))
            ans = min(ans, res);
    }

    if (ans == INF){
        puts("-1");
        return 0;
    }

    cout << ans << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const int INF = 1001001001;

struct RMQ {
  using Val = int;
  int n;
  vector<Val> vs;
  void clear(int N) {
    for (n = 1; n < N; n <<= 1);
    vs.assign(n * 2, INF);
  }
  Val get(int pos) {
    return vs[n+pos];
  }
  void update(int pos, Val val) {
    vs[n+pos] = val;
    for (int k = (n+pos)/2; k > 0; k >>= 1)
      vs[k] = min(vs[2*k], vs[2*k+1]);
  }
  // [l, r) の最小値を返す
  Val query(int l, int r) {
    return query(0, n, 1, l, r);
  }
  Val query(int nl, int nr, int k, int l, int r) {
    if (r <= nl || nr <= l) return INF;
    if (l <= nl && nr <= r) return vs[k];
    Val x = query(nl, (nl+nr)/2, 2*k  , l, r);
    Val y = query((nl+nr)/2, nr, 2*k+1, l, r);
    return min(x, y);
  }
};

const int MAX_N = 112345;
RMQ dp;

int main2() {
  int N = nextInt();
  int M = nextInt();
  string S; cin >> S;

  dp.clear(MAX_N);

  for (int i = N; i >= 0; i--) {
    if (i == N) {
      dp.update(N, 0);
    } else if (S[i] == '1') {
      dp.update(i, INF);
    } else {
      int t = dp.query(i+1, min(N+1, i+1+M));
      dp.update(i, t + 1);
    }
  }

  if (dp.get(0) >= INF/2) {
    cout << -1 << endl;
    return 0;
  }
  int pos = 0;

  while (pos != N) {
    int v = dp.query(pos + 1, pos + 1 + M);
    int m = 1;
    while (dp.get(pos + m) != v) m++;
    if (pos != 0) cout << " ";
    cout << m;
    pos += m;
  }
  cout << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1664