akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <tuple>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(Int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(Int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

const int MAX = 1003;
using Int = long long int ;
double ds[MAX];
double es[MAX][MAX];
struct Cir {
    Int x,y,r;
};
Cir cs[MAX];
Int n;
Int si, ti;

void solve() {
    int xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    cin >> n;
    si = 0;
    ti = n + 1;
    cs[si].x = xs;
    cs[si].y = ys;
    cs[si].r = 0;
    cs[ti].x = xt;
    cs[ti].y = yt;
    cs[ti].r = 0;
    REPCLS(i,n){
        cin >> cs[i].x >> cs[i].y >> cs[i].r;
    }
    double inf = numeric_limits<double>::max();
    FORCLS(i, si, ti) FORCLS(j, i, ti){
        Int dx = cs[i].x - cs[j].x;
        Int dy = cs[i].y - cs[j].y;
        double edge = sqrt(dx * dx + dy * dy);
        edge = max(0.0, edge - (cs[i].r + cs[j].r));
        es[i][j] = edge;
        es[j][i] = edge;
        
    }
    fill(ds, ds + ti + 1, inf);
    ds[0] = 0;
    
    priority_queue<pair<double,Int>> q;
    q.push(make_pair(-0, si));
    while(!q.empty()){
        Int i;
        double d;
        tie(d,i) = q.top(); q.pop();
        d = -d;
        if(i == ti) break;
        if(ds[ti] <= d) continue;
        
        FORCLS(j, si, ti){
            if(j == i) continue;
            double newD = d + es[i][j];
            if (newD < ds[j]){
                ds[j] = newD;
                q.push(make_pair(-newD, j));
            }
        }
    }
    printf("%.9f\n", ds[ti]);
}

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


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

int main(){
  int x,n,z=1000,ans=0;
  cin>>x>>n;
  vector<int>p(n+3);
  vector<int>a(10000);
  vector<int>b(10000);
  for(int i=1;i<=n;i++){
    cin>>p.at(i);
  }
  for(int i=0;i<=1000;i++){
    a.at(i)=i;
  }
  for(int i=0;i<=1000;i++){
    b.at(i)=i*(-1);
  }
  for(int i=1;i<=101;i++){
    for(int j=1;j<=n;j++){
      if(p.at(j)==a.at(i))a.at(i)=100000;
    }
  }
  for(int i=1000;i>=0;i--){
    if(z>=abs(x-a.at(i))){
      z=abs(x-a.at(i));
      ans=i;
    }
    if(z>=abs(x-b.at(i))){
      z=abs(x-b.at(i));
      ans=i;
    }
  }
  cout <<ans;
}


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

using namespace std;

vector<string> pos(int n)
{
    vector<string> v;
    if (n==1)
    {
        v.push_back("0");
        v.push_back("1");
    }
    else
    {
        vector<string> last = pos(n-1);
        for (int i=0;i<last.size();i++)
        {
            v.push_back("0"+last[i]);
            v.push_back("1"+last[i]);
        }
    }
    return v;
}

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

    int n, m;
    cin>>n>>m;
    int finale=0;

    vector<string> v = pos(n);

    int p[m];
    vector<int> bulbs[m];

    for (int i=0;i<m;i++)
    {
        int k;
        cin>>k;
        for (int l=0;l<k;l++)
        {
            int a;
            cin>>a;
            bulbs[i].push_back(a);
        }

    }

    for (int i=0;i<m;i++)
        cin>>p[i];

    for (int i=0;i<v.size();i++)
    {
        string pos = v[i];
        bool flag=true;
        for (int l=0;l<m;l++)
        {
            int sum = 0;
            for (int k=0;k<bulbs[l].size();k++)
            {
                sum+=(pos[bulbs[l][k]-1]);
            }
            if (sum%2!=p[l])
            {
                flag = false;
                break;
            }
        }
        if (flag)
            finale++;
    }
    cout<<finale;

}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<cctype>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-11;
const double pi = acos(-1.0); 
using namespace std;
using uint = unsigned int;
using int64 = long long;
using uint64 = unsigned long long;
#define ma = 2147483647;
#define mi = -2147483647;
const int N = 2e5 + 10;
int q[N];
long long t1[N];
long long t2[N];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> q[i];
	for (int i = 0; i < n; i++)
	{
		if (i + q[i] < n)
			t1[i + q[i]] ++;
		if (i - q[i] > 0)
			t2[i - q[i]] ++;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += t1[i] * t2[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 7532
#include<stdio.h>
#include<string.h>
int main()
{
	char x[200005];
	scanf("%s",x);
	int ans=0;
	int n=strlen(x);
	int i,a;
	a=0;
	for(i=0;i<n;i++)
	{
		if(x[i]=='S')
			a++;
		else if(a>0)
			a--;
		else
			ans++;
	}
	ans+=a;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
  int i,j,h,w;
  while(1)
    {
      scanf("%d%d",&h,&w);
      if(h==0&&w==0)break;
      for(i=0;i<h;i++)
	{
	  printf("#");
	  for(j=0;j<w-1;j++)
	    {
	      printf("#");
	    }
	  printf("\n");
	}
      printf("\n");
    }
      return 0;
    }

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

int main(){
  int H,W,K,res=0;
  cin >> H >> W >> K;
  vector<vector<char>> C(H,vector<char> (W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> C.at(i).at(j);
    }
  }
  for(int bitH=0;bitH<(1<<H);bitH++){
    for(int bitW=0;bitW<(1<<W);bitW++){
      int count=0;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(bitH &(1<<i)){
            continue;
          }
          if(bitW &(1<<j)){
            continue;
          }
          if(C.at(i).at(j)=='#'){
            count++;
          }
        }
      }
      if(count==K){
        res++;
      }
    }
  }
  cout << res << endl;
}

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


int judge(int n){
	if (n / 1000000 != 0) return 7;
	if (n / 100000 != 0) return 6;
	if (n / 10000 != 0) return 5;
	if (n / 1000 != 0) return 4;
	if (n / 100 != 0) return 3;
	if (n / 10 != 0) return 2;
	if (n / 1 != 0) return 1;
	return 0;
}


int main(){
	int a, b;
	while (cin >> a >> b)
	{
		int n = a + b;
		cout << judge(n) << endl;
	}

	return 0;
}


Measured memory_bytes: 2976
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
#define ls int len=s.size()
#define ls1 int len1=s1.size()
#define eps 1e-6
typedef long long int LL;
typedef long long int ll;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>

const int M = 1e5+100;
long long a[M],b[M],c[M],ans,t,s;
int n;
bool init(){
    s=0;
    for(int i=0;i<n;i++){scanf("%lld",&a[i]);s+=a[i];}
    for(int i=1;i<n;i++) b[i-1]=a[i]-a[i-1];
    b[n-1]=a[0]-a[n-1];
    t=(long long)n*(n+1)/2;
    if(s%t) return 0;
    s=s/t;ans=0;
    for(int i=0;i<n;i++){
        if(s-b[i]<0||(s-b[i])%n) return 0;
        ans+=(s-b[i])/n;
    }
    if(ans==s) return 1;
    else return 0;
}

int main(){
#ifdef LOCAL
	freopen("data.h", "r", stdin);
	freopen("1.h","w",stdout);
#endif
    while(~scanf("%d",&n)){
        if(init()) puts("YES");
        else puts("NO");
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> t(N), v(N), s(N+1, 0);
    REP(i, N) cin >> t[i];
    REP(i, N) cin >> v[i];
    REP(i, N) v[i] *= 2;
    REP(i, N) t[i] *= 2;
    REP(i, N) s[i+1] = s[i] + t[i];

    ll T = 0;
    REP(i, N) T += t[i];

    vector<ll> poi(T+1);
    const ll INF = (1ll<<60);
    for(ll t=0;t<=T;t++){
        ll val = INF;
        REP(i, N){
            if(t<=s[i]){
                chmin(val, -t+s[i]+v[i]);
            }else if(t>=s[i+1]){
                chmin(val, t-s[i+1]+v[i]);
            }else{
                chmin(val, v[i]);
            }
        }
        chmin(val, t);
        chmin(val, T-t);
        poi[t] = val;
    }

    double res = 0;
    REP(i, T){
        res += (poi[i] + poi[i+1]);
    }

    printf("%.10f\n", res/8.0);
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict
n,x,y=map(int,input().split())
d=defaultdict(lambda:0)
for i in range(1,n):
      for j in range(i+1,n+1):
            l=min(j-i,abs(j-x)+abs(i-y)+1,abs(i-x)+abs(j-y)+1)
            d[l]+=1
for i in range(1,n):
      print(d[i])

Measured memory_bytes: 50524
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;
    lli n;
    cin>>n;
    vlli v;
    lli a;
    while(n--)
    {
        cin>>a;
        v.pb(a);

    }
    UN(v);
    cout<<v.sz();
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <list>

#define pb push_back
#define pk pop_back
#define _for(i,j,k) for(long i = (j); i < (k); ++i)

using namespace std;

struct cake{
    long long taka;
    long long aoki;
    cake(long long t,long long k):taka(t),aoki(k){;}
    bool operator<(const cake& a)const{
        return taka+aoki > a.aoki + a.taka;
    }
};

int main()
{
    vector<cake> vck;
    long long N,t,k,t_sum,k_sum;
    t_sum = 0;
    k_sum = 0;
    scanf("%lld",&N);

    _for(i,0,N){
        scanf("%lld %lld",&t,&k);
        vck.pb(cake(t,k));
    }

    sort(vck.begin(),vck.end());

    _for(i,0,N){
        if(i%2 == 0){
            t_sum += vck[i].taka;
        }
        else{
            k_sum += vck[i].aoki;
        }
    }
    printf("%lld\n",t_sum-k_sum);
}

Measured memory_bytes: 2420
#ABC130 C-Rectangle Cutting 14:59

W,H,x,y = map(int, input().split())

def func(W,H,x,y):
    if x* 2 == W and y*2 == H:
        return W*H/2, 1
    else:
        return W*H/2, 0
print(*func(W,H,x,y))

Measured memory_bytes: 9112
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        d: usize,
        t: usize,
        s: usize
    }

    let mut ans = 0;

    if s * t >= d {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> x(N);
    vector<vector<int>> y(N);
    for (int i=0; i<N; i++)
    {
        int A;
        cin>>A;
        for (int j=0; j<A; j++)
        {
            int tx, ty;
            cin>>tx>>ty;
            x[i].push_back(tx-1);
            y[i].push_back(ty);
        }
    }

    int ans = 0;
    for (int b=0; b<1<<N; b++)
    {
        bool ok = true;
        for (int i=0; i<N; i++)
            if (b>>i&1)
                for (int j=0; j<(int)x[i].size(); j++)
                    if ((b>>x[i][j]&1) != y[i][j])
                        ok = false;
        if (ok)
        {
            int c = 0;
            for (int i=0; i<N; i++)
                c += b>>i&1;
            ans = max(ans, c);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i;
  int n;
  int min = 1000000, max = -1000000;
  long long sum = 0;
  int a;

  scanf("%d\n",  &n);

  for (i = 0; i < n; i++) {
    char c;
    int ret;
    ret = scanf("%d%c", &a, &c);
    if (a <= min) {
      min = a;
    }
    if (a >= max) {
      max = a;
    }
    sum += a;

    if (ret == 1) break;
  }

  printf("%d %d %lld\n", min, max, sum);
  
  return 0;
}
    


Measured memory_bytes: 2144
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
   public static void main(String args[])
   {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int a[]=new int[n];
       int b[]=new int[n];
       int c[]=new int[n];
       for(int i=0;i<n;i++)
       {
           a[i]=sc.nextInt();
           b[i]=sc.nextInt();
           c[i]=sc.nextInt();
       }
       int dp[][]=new int[n][3];
       dp[0][0]=a[0];
       dp[0][1]=b[0];
       dp[0][2]=c[0];
       for(int i=1;i<n;i++)
       {
           dp[i][0]=Math.max(dp[i-1][1],dp[i-1][2])+a[i];
           dp[i][1]=Math.max(dp[i-1][0],dp[i-1][2])+b[i];
           dp[i][2]=Math.max(dp[i-1][1],dp[i-1][0])+c[i];
       }
       dp[n-1][2]=Math.max(dp[n-1][2],dp[n-1][1]);
       dp[n-1][2]=Math.max(dp[n-1][2],dp[n-1][0]);
       System.out.println(dp[n-1][2]);
   }
}

Measured memory_bytes: 93172
#include <stdio.h>
#include <string.h>
int main(){
int n, a , ab, ctr = 0, flag = 0;
scanf("%d", &n);
for(int i = 0;i < n;i++){
	scanf("%d %d", &a, &ab);
	if(a == ab){
		ctr++;
	}else{
		ctr = 0;
	}
	if(ctr >= 3){
		flag = 1;
	}
}
flag == 1 ? printf("Yes") : printf("No");
return 0;
}



Measured memory_bytes: 1736
N, K = map(int,input().split())
MOD = 10**9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD

for k in range(K):
    if k > N-K:
        print(0)
    else:
        print((nCr(K-1,k)*nCr(N-K+1,k+1))%MOD)


Measured memory_bytes: 27160
import java.util.Scanner;
import java.util.Vector;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		Vector<Integer> v=new Vector<Integer>();

		for(int i=0; i<n; i++) {
			int z=sc.nextInt();
			z--;
			v.add(z);
		}
		int now=0; int c=0;
		for(;;) {
			if(now==1) {
				System.out.println(c);
				break;
			}
			if(c>=n) {
				System.out.println(-1);
				break;
			}
			c++;
			now=v.get(now);
		}
	}
}

Measured memory_bytes: 59876
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

typedef string::const_iterator State;
class ParseError {};

int expression(State &begin);

int number(State &begin) {
    int ret = 0;
    
    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    
    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
int factor(State &begin) {
    if (*begin == '(') {
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    }else{
        return number(begin);
    }
}

int term(State &cur) {
    int ret = factor(cur);
    
    while(*cur=='*' || *cur=='/'){
        if (*cur == '*') {
            cur++;
            ret *= factor(cur);
        } else if (*cur == '/') {
            cur++;
            ret /= factor(cur);
        }
    }
    
    return ret;
}

int expression(State &cur) {
    int ret = term(cur);
    
    while(*cur=='+' || *cur=='-'){
        if (*cur == '+') {
            cur++;
            ret += term(cur);
        } else if (*cur == '-') {
            cur++;
            ret -= term(cur);
        }
    }
    
    return ret;
}

int main(void) {
    int N; cin >> N;
    while(N--){
        string s;
        cin >> s;
        State cur = s.begin();
        cout << expression(cur) << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    if (N == 1) {
        cout << M << endl;
        return 0;
    }

    ll ans = 1;
    for (ll i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            if (i >= N) {
                ans = max(ans, M / i);
            } else if (M / i >= N) {
                ans = max(ans, i);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    fast;
    int i,j,c=0,d=0,n,h,a;
    cin>>h>>a;
    for(i=1;i<10000000;i++)
    {
        h=h-a;
        if(h<=0)
        {
            break;
        }
    }
    cout<<i;



}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;

  if(a <= 0 && 0 <= b ){
    cout << "Zero" << endl;
  }else if(b < 0){
    if((abs(a-b)+1)%2 == 0){
      cout << "Positive" << endl;
    }else{
      cout << "Negative" << endl;
    }
  }else if(a > 0){
    cout << "Positive" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import collections

N = int(input().split()[0])
a_list = list(map(int, input().split()))

excepted_dict = {}

if N % 2 == 0:
    n = N // 2
    expected_dict = {i * 2 + 1: 2 for i in range(n)}
else:
    n = N // 2
    expected_dict = {i * 2: 2 for i in range(n + 1)}
    expected_dict[0] = 1

counter = collections.Counter(a_list)

mod = 10 ** 9 + 7

if dict(counter) == expected_dict:
    c = 1
    for v in counter.values():
        c = ((c % mod) * (v % mod)) % mod
    ans = c
else:
    ans = 0

print(ans)


Measured memory_bytes: 21344
def calc(n, l, s, t, u)
  ok = proc do |m|
    w, e, f = l.to_f, [], true
    2.times do |j|
      w = [w + m * s[0], l].min
      n.times do |i|
        w += (m - u[i]) * (t[i] - s[i])
        if w <= 0
          f = false
          break
        end
        w += m * (s[i + 1] - t[i]) if i < n - 1
        w = l if w > l
      end
      break unless f
      w = [w + m * (86400 - t[-1]), l].min
      e[j] = w
    end
    f && e[1] >= e[0]
  end
  ll, rr = 0.0, 1e6
  loop do
    m = (ll + rr) / 2
    return m if rr - ll < 1e-7
    if ok.call(m)
      rr = m
    else
      ll = m
    end
  end
end
loop do
  n, l = gets.split.map(&:to_i)
  break if n == 0
  s, t, u = [], [], []
  n.times do |i|
    s[i], t[i], u[i] = gets.split.map(&:to_i)
  end
  puts format('%.7f', calc(n, l, s, t, u))
end

Measured memory_bytes: 14068
import java.io.*
import java.util.*

const val YES = "POSSIBLE"
const val NO = "IMPOSSIBLE"
fun solve(N: Int, M: Int, a: IntArray, b: IntArray){
    val fromOne = a.withIndex().filter{ it.value == 1 }.map{ b[it.index] }.toSet()
    val toN = b.withIndex().filter{ it.value == N }.map{ a[it.index] }.toSet()
    if ((fromOne intersect toN).isEmpty()) println(NO)
    else println(YES)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val a = IntArray(M)
    val b = IntArray(M)
    for (i in 0 until M) {
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
    }
    solve(N, M, a, b)
}



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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int> > dp(n, vector<int>(n));
    dp.at(0).at(0) = 0;
    rep(i,n-1){
        for(int j=i+1,count=j-i;j<n;++j){
            if(s[i] == s[j]){
                
                int oldp = 0;
                if(i != 0)
                    oldp = dp.at(i-1).at(j-1);
                if(j-oldp == i) oldp=0;
                dp.at(i).at(j) = oldp + 1;
                
                }else
                dp.at(i).at(j) = 0;                
        }
    }
    vector<int> ans;
    rep(i,n){
        sort(dp.at(i).begin(),dp.at(i).end());
        ans.push_back(dp.at(i).back());
    }
    sort(ans.begin(),ans.end());
    cout<<ans.back()<<endl;
}

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



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	int g = __gcd(n,m);
	bool ok=true;
	for(int i=0,j=0;i<n;i+=n/g,j+=m/g)
		if(s[i]!=t[j])
			ok=false;
	if(ok)
		cout<<1LL*n*m/g<<endl;
	else
		cout<<-1<<endl;
}


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

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

const int LIM = 1e5+10;
ll pd[LIM], h[LIM];
bool calc[LIM];

int N, K;

ll solve(int n = 0){
    if(n>=N) return INF;
    if(n == N-1) return 0;
    if(calc[n]) return pd[n];
    calc[n] = 1;
    
    pd[n] = abs(h[n+1]-h[n])+solve(n+1);
    for(int i=2; i<=K; i++){
        pd[n] = min(pd[n], abs(h[n+i]-h[n]) + solve(n+i));
    }
    return pd[n];
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> h[i];
    cout << solve() << '\n';

    return 0;
}


Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
	static void Main() {
		var A = NextInt();
		var B = NextInt();
		var C = NextInt();
		var K = NextInt();

		var L = new int[] { A, B, C };

		WriteLine(L.Sum() + L.Max() * (Math.Pow(2, K) - 1));
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 13268
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

void solve(int n, int x, vector<int> &m){
    sort(ALL(m));
    lint ans = n;
    lint sum = 0;
    lint rest = x;
    REP(i, n){
        sum += m[i];
    }
    rest -= sum;
    ans += rest / m[0];
    cout << ans << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    REP(i, n){
        cin >> m[i];
    }
    solve(n, x, m);
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
n,m=map(int,input().split())
g=[[]for i in range(n)]; ans=0
for i in range(m):
  a,b=map(int,input().split())
  a-=1; b-=1
  g[a].append(b)
  g[b].append(a)
# print(g)
def dfs(x,visited):
  global ans
  # print(x,visited)
  for p in g[x]:
    if visited[p]==0:
      visited[p]=1
      if visited.count(1)==n:
        ans+=1
        # print(ans)
      else: 
        dfs(p,visited)
      visited[p]=0
v=[0]*n
v[0]=1
dfs(0,v)
print(ans)

Measured memory_bytes: 3064
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))

n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    if a1[i] in b:
        a1[i] = "o"
        
for i in range(3):
    if a2[i] in b:
        a2[i] = "o"
        
for i in range(3):
    if a3[i] in b:
        a3[i] = "o"
        
if a1[0]==a1[1]==a1[2] or a2[0]==a2[1]==a2[2] or a3[0]==a3[1]==a3[2] or a1[0]==a2[0]==a3[0] or a1[1]==a2[1]==a3[1] or a1[2]==a2[2]==a3[2] or a1[0]==a2[1]==a3[2] or a1[2]==a2[1]==a3[0]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#define max(x,y)((x)>(y)?(x):(y))
#define min(x,y)((x)<(y)?(x):(y))
char map[501*500];
struct{
	int h,s;
}DP[501][501];
int main(){
	int H,W,i,x,y,w,h,s,S;
	for(;scanf("%d%d\n",&H,&W),H;){
		for(i=0;i<(W+1)*H;i++)
			map[i]=getchar();
		memset(DP,0,sizeof(DP));
		S=0;
		for(y=1;y<=H;y++){
			for(x=1;x<=W;x++){
				if(map[(y-1)*(W+1)+(x-1)]=='.'){
					h=DP[x][y].h=DP[x][y-1].h+1;
					s=h;
					for(w=2;h;w++){
						h=min(h,DP[x-w+1][y].h);
						s=max(s,w*h);
					}
					DP[x][y].s=s;
					S=max(S,s);
				}else{
					DP[x][y].h=0;
				}
			}
		}
		/*
		for(y=1;y<=H;y++){
			for(x=1;x<=W;x++)
				printf(" %x",DP[x][y].h);
			printf("   ");
			for(x=1;x<=W;x++)
				printf(" %2d",DP[x][y].s);
			puts("");
		}*/
		printf("%d\n",S);
		//puts("");
		
	}
	exit(0);
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << setprecision(20) << (B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B / (C * D / __gcd(C, D)) - (A - 1) / (C * D / __gcd(C, D)));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define inf (int)1e9
int main() {
     
    fio;
    string s;
    cin>>s;
    if(s=="ABC")
    {
	    cout<<"ARC\n";
    }
    else
    {
	    cout<<"ABC\n";
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define N 100005
#define M 30
using namespace std;
int n,k,c,depth[N],parent[N][M];
vector<int> e[N];

void dfs(int x,int d){
  depth[x]=d;
  for(int i=0;i<(int)e[x].size();i++)
    dfs(e[x][i],d+1);
}

int lca(int u,int v){
  if(depth[u]<depth[v])swap(u,v);
  int K=depth[u]-depth[v];
  for(int i=0;i<M;i++)
    if(K>>i&1)u=parent[u][i];
  if(u==v)return u;
  for(int j=M-1;j>=0;j--){
    if(parent[u][j]==parent[v][j])continue;
    u=parent[u][j];
    v=parent[v][j];
  }
  return parent[u][0];
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      scanf("%d",&c);
      e[i].push_back(c);
      parent[c][0]=i;
    }
  }
  for(int j=1;j<M;j++)
    for(int i=0;i<n;i++)
      parent[i][j]=parent[parent[i][j-1]][j-1];
  dfs(0,0);
  int q,u,v;
  cin>>q;
  for(int i=0;i<q;i++){
    scanf("%d%d",&u,&v);
    printf("%d\n",lca(u,v));
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct ant { ll X; ll W; };

int main() {
  ll N, L, T; cin >> N >> L >> T;
  ant a[N]; rep(i,N) { ll X, W; cin >> X >> W; a[i] = {X,W}; }
  ll pos[N]; rep(i,N) pos[i] = ((a[i].X+T*(a[i].W==1?1:-1))%L+L)%L;

  if (N==1) { cout << pos[0] << endl; return 0; }

  ll count0 = 0;
  rep(i,N) {
    if (a[0].W!=a[i].W)  {
      ll diff;
      if (a[0].W==1) diff = (L-(a[i].X-a[0].X+L)%L) + 2*T;
      else diff = (L-(a[0].X-a[i].X+L)%L) + 2*T;
      count0 += diff/L;
      count0 %= N;
    }
  }
  ll p0 = a[0].W==1 ? count0 : (N-count0)%N;
  // cout << p0 << endl; debug(pos,pos+N);

  ll result[N] = {}; result[p0] = pos[0];
  ll tp = pos[1];
  sort(pos,pos+N);
  int p;
  if (a[0].W==1) p = upper_bound(pos,pos+N,result[p0]) - pos - 1;
  else p = lower_bound(pos,pos+N,result[p0]) - pos;
  rep(i,N) result[(p0+i)%N] = pos[(p+i)%N];
  rep(i,N) cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){
    char tmp[1000];
    //??\???
    fgets(tmp,sizeof(tmp),stdin);
    int num[3];
        num[0]=atoi(strtok(tmp," "));
    int i;
    for(i=1;i<3;i++){
        num[i]=atoi(strtok(NULL," "));
    }
    int j;
    for(i=0;i<3;i++){
        for(j=i+1;j<3;j++){
            if(num[i]>num[j]){
                int tmp=num[i];
                num[i]=num[j];
                num[j]=tmp;
            }   
        }
        if(i<2){
            printf("%d ",num[i]);
        } else{
            printf("%d\n",num[i]);
        }
    }
return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
T Prim(WeightedGraph<T> &g)
{
    T res = 0;
    vector<bool> used(g.size(), false);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
    que.emplace(0, 0);
    while (que.empty() != true)
    {
        auto p = que.top();
        que.pop();
        if (used[p.second] == true)
            continue;
        used[p.second] = true;
        res += p.first;
        for (auto &e : g[p.second])
        {
            que.emplace(e.cost, e.to);
        }
    }
    return res;
}

int N;
ll a, b;

int main()
{
    cin >> N;
    vector<pair<pair<ll, ll>, int>> x, y;
    WeightedGraph<ll> G(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a >> b;
        a--, b--;
        x.emplace_back(make_pair(a, b), i);
        y.emplace_back(make_pair(b, a), i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    for (int i = 0; i + 1 < N; i++)
    {
        ll a = x[i].first.first, b = x[i].first.second;
        ll na = x[i + 1].first.first, nb = x[i + 1].first.second;
        int p1 = x[i].second, p2 = x[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - na), abs(b - nb)));
        G[p2].emplace_back(p1, min(abs(a - na), abs(b - nb)));
    }

    for (int i = 0; i + 1 < N; i++)
    {
        ll a = y[i].first.first, b = y[i].first.second;
        ll na = y[i + 1].first.first, nb = y[i + 1].first.second;
        int p1 = y[i].second, p2 = y[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - na), abs(b - nb)));
        G[p2].emplace_back(p1, min(abs(a - na), abs(b - nb)));
    }
    cout << Prim(G) << endl;
}

Measured memory_bytes: 24996
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in); 
		
		int H, W;
		
		for(;;){

			H = scan.nextInt();
			W = scan.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			for(int i = 0; i < H; i++){
				if(i == 0 || i == H - 1){
					sharpLine(W);
				}else{
					sharpDotLine(W);
				}
			}
			System.out.println();
		}
	}
	
	static void sharpLine(int w){
		for(int i = 0; i < w; i++){
			System.out.print("#");
		}
		System.out.println();
	}
	
	static void sharpDotLine(int w){
		for(int i = 0; i < w; i++){
			if(i == 0 || i == w - 1){
				System.out.print("#");
			}else{
				System.out.print(".");
			}
		}
		System.out.println();
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> h(n), h2(n);
  int num = 0;
  for(int i = 0; i < n; i++)
  {
    cin >> h.at(i);
  }
  
  while(true){
    vector<int> hh(n);
    int p, k = 0;
    for(int i = 0; i < n; i++)
    {
      if (h.at(i) >= 1) {
        h.at(i) -= 1;
        hh.at(i) = 1;
      }
      else
      {
        hh.at(i) = 0;
      }



      if (i == 0) {
        if (hh.at(i) == 1) {
          p = 1;
          k = 1;
        }
        else
        {
          p = 0;
          k = 0;
        }
      }
      
      else if (i > 0) {
        if (hh.at(i) != p){
          if (p == 1) {
            p = 0;
          }
          else
          {
            k+=1;
            p = 1;
          }
          
          
        }
        
      }
              
    }
    num += k;
    if (h == h2) {
      break;
    }
    

    
  }
  cout << num << endl;
  
}

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

int main(){
 int N, M;
 int L = 1, R = N;
 int ans = 0;

 cin >> N >> M;
 
 for(int i = 0; i < M ; i++){
   int x, y;
   cin >> x >> y;
   L = max(x, L);
   R = min(y, R);
 }
 
 for(int i = 1; i <= N ; i++){
  if( i >= L and i <= R) ans += 1;
 }

 cout << ans << endl;
  
}

Measured memory_bytes: 384
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

def make_tree(pos, id, S, V, E):
    if S[pos] == ')':
        V[id] = -1
        return pos + 1, id + 1
    par = id
    id += 1
    E[par][0] = id
    pos, id = make_tree(pos + 1, id, S, V, E)
    val = ''
    pos += 1
    while S[pos] != ']':
        val += S[pos]
        pos += 1
    V[par] = int(val)
    pos += 1
    E[par][1] = id
    pos, id = make_tree(pos + 1, id, S, V, E)
    return pos + 1, id

def and_tree(id1, id2, V1, V2, E1, E2):
    if V1[id1] == -1 or V2[id2] == -1:
        return ""
    S = ""
    S += "(" + and_tree(E1[id1][0], E2[id2][0], V1, V2, E1, E2) + ")"
    S += "[" + str(V1[id1] + V2[id2]) + "]"
    S += "(" + and_tree(E1[id1][1], E2[id2][1], V1, V2, E1, E2) + ")"
    return S

S1 = raw_input()
V1 = [-1] * 1000
E1 = [[-1, -1] for i in range(1000)]
make_tree(0, 0, S1, V1, E1)

S2 = raw_input()
V2 = [-1] * 1000
E2 = [[-1, -1] for i in range(1000)]
make_tree(0, 0, S2, V2, E2)

print and_tree(0, 0, V1, V2, E1, E2)


Measured memory_bytes: 5384
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    N = int(input())
    if N % 2 == 1:
        return 0
    d = 10
    m = 1
    ret = 0
    while d <= N:
        ret += m * (N // d)
        d *= 5
    return ret


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 13668
#!usr/bim/python
#! -*- coding: utf-8 -*-

nmk = raw_input()
nmk = nmk.split()
n,m,k = map(int,nmk)

status = 0

for i in range(m+1):
    for j in range(n+1):
        if n*i + m*j - 2*i*j == k:
            status = 1
            break

if status == 0:
    print "No"
else:
    print "Yes"


Measured memory_bytes: 2692
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>

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

  std::vector<int> p(N);
  std::copy_n(std::istream_iterator<int>(std::cin),N,p.begin());

  int count = 0;
  for(int i = 1 ; i <= (int)p.size() ; i++){
    if(i != p[i-1]){
      count++;
    }
  }

  if(count == 0 || count == 2){
    std::cout << "YES" << std::endl;
  }else{
    std::cout << "NO" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b, i, n;
    char op;
    i = 1;
    while (i == 1){
        cin >>a >> op >> b;
        if(op == '?') break;
        else if(op == '+') n = a + b;
        else if(op == '-') n = a - b;
        else if(op == '*') n = a*b;
        else if(op == '/') n = a/b;
        cout << n << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int n1,int n2)
{
	if(n1>n2)
		return n2;
	else
		return n1;
}
long int reach(int i,int a[],int memo[],int k)
{
	if(i<2)
		return 1000000000;
	if(i==2)
		return 0;
	if(memo[i]!=-1)
		return memo[i];
	else
	{
		long int q=1000000000,j,m;
		if(k+2<=i)
			m=k;
		else
			m=i-2;
		for(j=1;j<=m;j++)
		q=min(q,fabs(a[i]-a[i-j])+reach(i-j,a,memo,k));
		memo[i]=q;
		return memo[i];
	}
}
int main()
{
      int a[1000009],memo[1000009],n,k;
      scanf("%d %d",&n,&k);
      for(int i=2;i<=n+1;i++)
      {
      scanf("%d",&a[i]);
      memo[i]=-1;
      }
      printf("%ld\n",reach(n+1,a,memo,k));
		      return 0;
		      }


Measured memory_bytes: 15616
# coding: utf-8

def main():
    N,M,C = map(int,input().split())
    B = list(map(int,input().split()))
    # print(B)
    ans = 0
    for i in range(N):
        temp_A = list(map(int,input().split()))
        temp = 0
        for j in range(M):
            temp += temp_A[j]*B[j]
        if temp + C > 0:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
n,x=map(int, input().split())
p=[1]*(n+1) #パティ
a=[1]*(n+1) #パティとバンズ

for i in range(1,n+1):
    p[i]=p[i-1]*2+1
    a[i]=a[i-1]*2+3

def f(n,x):
    if x==0:
        return 0
    if n==0:
        return 1
    
    center = a[n-1] + 2
    
    if x < center:
        return f(n-1,x-1)
    elif x >= center:
        return p[n-1] + 1 + f(n-1,x-center)

print(f(n,x))

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

const int Max=200000;
int n,m,q,ans;
int f[501][501];

inline int get_int()
{
	int x=0,f=1;
	char c;
	for(c=getchar();(!isdigit(c))&&(c!='-');c=getchar());
	if(c=='-') {f=-1;c=getchar();}
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	return x*f;
}

inline void print(int x)
{
	if(x>9) print(x/10);
	putchar('0'+x%10);
}

int main()
{
	n=get_int(),m=get_int(),q=get_int();
	for(int i=1;i<=m;i++)
	{
	  int x=get_int(),y=get_int();
	  f[x][y]++;
	}
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++) f[i][j]=f[i][j-1]+f[i][j];
	while(q--)
	{
	  ans=0;
	  int x=get_int(),y=get_int();
	  for(int i=x;i<=y;i++) ans+=f[i][y];
	  print(ans),putchar('\n');
	}
	return 0;
}

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

int n,m,x;

int minCost (int idx, vector<int> &myStatus, vector<int> &cost, vector<vector<int>> &books)
{
  int j;
  for (j=0;j<m;j++)
    if (myStatus[j]<x)
      break;
  
  if (j==m)
    return 0;
  
  if (idx==n)
  	return INT_MAX;    
  
  for (int i=0;i<m;i++)
    myStatus[i]+=books[idx][i];
  
  int cost1 = minCost (idx+1,myStatus,cost,books);
  if (cost1<INT_MAX)
    cost1+=cost[idx];
  
  for (int i=0;i<m;i++)
    myStatus[i]-=books[idx][i];
  
  int cost2 = minCost (idx+1,myStatus,cost,books);
  
  return min (cost1,cost2);
}

int main()
{
  cin>>n>>m>>x;
  
  vector<int> myStatus (m,0);
  vector<int> cost (n,0);
  vector<vector<int>> books(n,vector<int> (m,0));
  
  for (int i=0;i<n;i++)
  {
    cin>>cost[i];
    
    for (int j=0;j<m;j++)
      cin>>books[i][j];
  }
  
  int ans = minCost (0,myStatus,cost,books);
  
  if (ans==INT_MAX)
    cout<<-1;
  else
    cout<<ans;
  
  
  
}

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

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

   vector<int> R, L;
   vector<int> ans(S.length(), 0);

   rep(i, S.length()) {
     if (S.at(i) == 'R') R.push_back(i * (-1));
     else if (S.at(i) == 'L') L.push_back(i);
   }

   sort(R.begin(), R.end());

   rep(i, S.length()) {
     if (S.at(i) == 'R') {
       auto itr = lower_bound(L.begin(), L.end(), i);
       if ((*itr - i) % 2 == 0) ans.at(*itr)++;
       else ans.at(*itr - 1)++;
     }
     if (S.at(i) == 'L') {
       auto itr = lower_bound(R.begin(), R.end(), -i);
       if ((i + *itr) % 2 == 0) ans.at(*itr * (-1))++;
       else ans.at(*itr * (-1) + 1)++;
     }
   }

   rep(i, S.length() - 1) {
     cout << ans.at(i) << " ";
   }
   cout << ans.at(S.length() - 1) << endl;
 }


Measured memory_bytes: 1532
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;


int main() {
    int N,M;
    int t, a;

   

    cin >> N;
    cin >> t >> a;
    int H[N];
    double min = 1000000;
    int idx = 0;
    for (int i = 0; i < N; i++)
    {
        int c;
        cin >> c;
        double b = t - c * 0.006-a;
        if(b<0){
            b = -b;
        }
        if(b<min){
            min = b;
            idx = i + 1;
        }
    }
    cout << idx << endl;
}

Measured memory_bytes: 256