akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve(s: &[char]) -> bool {
    let a = &s[0..(s.len() / 2)];
    let b = &s[(s.len() / 2 + (s.len() % 2))..(s.len())];
    let b_clone = &mut vec!['0'; b.len()][..];
    b_clone.clone_from_slice(b);
    b_clone.reverse();
    // println!("{:?}, {:?}", a, b_clone);
    a == b_clone
}

fn main() {
    input! {
        s: chars,
    }
    let a = solve(&s[..]);
    let b = solve(&s[0..((s.len() - 1) / 2)]);
    let c = solve(&s[((s.len() + 3) / 2 - 1)..(s.len())]);
    // println!("{:?}", &s[((s.len() + 3) / 2 - 1)..(s.len())]);
    println!("{}", if a && b && c { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    var b: String = readLine()!!
    when (b) {
        "A" -> {
            println("T")
        }
        "T" -> {
            println("A")
        }
        "C" -> {
            println("G")
        }
        "G" -> {
            println("C")
        }
    }
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N;
vector<int> G[10000];
vector<bool> visit(10000, false);
vector<int> ans(10000);
vector<ll> c;
int pos = 0;

void dfs(int p) {
  visit[p] = true;
  ans[p] = c[pos];
  pos++;
  REP(i, G[p].size()) {
    int q = G[p][i];
    if (visit[q]) continue;
    dfs(q);
  }
}

int main() {
  cin >> N;
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(i, N) {
    ll score;
    cin >> score;
    c.push_back(score);
  }
  sort(ALL(c));
  ll sum = 0;
  REP(i, N - 1) sum += c[i];
  cout << sum << endl;
  reverse(ALL(c));
  dfs(0);
  REP(i, N) {
    if (i != 0) cout << " ";
    cout << ans[i];
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 1404
#include <stdio.h>
#include <math.h>

double get_radian(double x1, double y1, double x2, double y2) {
	if(fabs(x1-x2) < 0.00000001f) {
		if(fabs(y1-y2) < 0.00000001f) {
			return 0.0f;
		} else if(y1 > y2) {
			return 3 * M_PI / 2;
		} else {
			return M_PI / 2;
		}
	} else if(fabs(y1-y2) < 0.00000001f) {
		if(fabs(x1-x2) < 0.00000001f) {
			return 0.0f;
		} else if(x1 > x2) {
			return M_PI;
		}
		return 0.0;
	}
	
	if(x2 >= x1) {
		if(y2 >= y1) {
			return atan((y2-y1)/(x2-x1));
		}
		return 2 * M_PI + atan((y2-y1)/(x2-x1));
	} else {
		if(y2 >= y1) {
			return M_PI - atan((y2-y1)/(x1-x2));
		}
		return M_PI + atan((y2-y1)/(x2-x1));
	}
}

int main(void) {
	double base_x, base_y, x, y;
	double base_rad, target_rad;
	double rad;
	double r1, r2, rdiff;
	int i, n;
	
	scanf("%lf %lf %lf %lf\n", &base_x, &base_y, &x, &y);
	scanf("%d\n", &n);
	base_rad = get_radian(base_x, base_y, x, y);
	r1 = sqrt((x-base_x)*(x-base_x)+(y-base_y)*(y-base_y));
	
	for(i=0;i<n;i++) {
		scanf("%lf %lf\n", &x, &y);
		target_rad = get_radian(base_x, base_y, x, y);
		r2 = sqrt((x-base_x)*(x-base_x)+(y-base_y)*(y-base_y));
		
		rdiff = fmod(2*M_PI+target_rad-base_rad, 2*M_PI);

		if(fabs(r1) < 0.0001) {
			printf("ONLINE_FRONT\n");
		} else if(fabs(r2) < 0.0001) {
			printf("ON_SEGMENT\n");
		} else if(fabs(rdiff) < 0.00001) {
			if(r2 > r1) {
				printf("ONLINE_FRONT\n");
			} else {
				printf("ON_SEGMENT\n");
			}
		} else if(fabs(rdiff-M_PI) < 0.00001) {
			printf("ONLINE_BACK\n");
		} else if(rdiff < M_PI) {
			printf("COUNTER_CLOCKWISE\n");
		} else {
			printf("CLOCKWISE\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 700
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int score = 0;

        for (int i = 0; i < s.length(); i++) {
            switch (s.charAt(i)) {
                case '+':
                    score += 1;
                    break;
                case '-':
                    score -= 1;
                    break;
                default:
                    break;
            }
        }

        System.out.println(score);
    }
}


Measured memory_bytes: 21844
s=list(input())
n=len(s)

def dfs(i,f):
    if i==n-1:
        return sum(list(map(int,f.split("+"))))
    
    return dfs(i+1,f+s[i+1]) + dfs(i+1, f + "+" + s[i+1])


print(dfs(0,s[0]))

Measured memory_bytes: 3060
import java.util.Scanner;

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

	int n=scanner.nextInt();
	if(n>=30){
      	System.out.println("Yes");
    }
       else{
         	System.out.println("No");
       }

	 }
}

Measured memory_bytes: 35632
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

ll n, ans;
vector<int> v[200100];
pii a[200100];

void dfs(ll a, ll f) {
    for(int i : v[a]) {
        if(i == f) continue;
        if(i < a) {
            dfs(i, a);
            ans += i * (a - i);
        } else if(i > a) {
            dfs(i, a);
            ans += (i - a) * (n - i + 1);
        }
    }
}

int main() {Tie
    cin >> n;
    for(int i = 1, x, y; i < n; i++)
        cin >> x >> y, v[x].pb(y), v[y].pb(x);

    dfs(1, 0);
    cout << ans + n << '\n';
}


Measured memory_bytes: 26968
N, M = map(int, input().split())

A = [0] *  N
for n in range(N):
    A[n] = list(map(int, input().split()))

A.sort()
p = 0
v = 0
for a in A:
    p += a[1]
    v += a[0] * a[1]
    if p >= M:
        v -= a[0] * (p - M)
        print(v)
        exit()



Measured memory_bytes: 27888
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[110];
int main()
{
  ll n;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
  ll flag = 1, ans = 0;
  while (flag)
  {
    int i = 0;
    while (i < n)
    {
      if (a[i] == 0)
        i++;
      else
      {
        ans++;
        while (a[i] > 0)
        {
          a[i]--;
          i++;
        }
      }
    }
    flag = 0;
    for (int i = 0; i < n; i++)
    {
      if (a[i] != 0)
        flag = 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ff first
#define se second
using namespace std;
int n,m,a,b,c,d,k;
const int inf=1e8+5;
queue<pair<pair<int,int>,int> > q;
bool cek(int a,int b)
{
	if(a>=1&&a<=n&&b>=1&&b<=m) return true;
	return false;
}
int main()
{
	cin>>n>>m>>k>>a>>b>>c>>d;
	int flag[n+2][m+2]={inf};
	char arr[n+2][m+3]={'*'};
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) cin>>arr[i][j];
	}
	q.push({{a,b},0});
	flag[a][b]=0;
	while(!q.empty())
	{
		int x,y,z;
		x=q.front().ff.ff;
		y=q.front().ff.se;
		z=q.front().se;
		q.pop();
		//cout<<x<<" "<<y<<" "<<z<<endl;
		if(x==c&&y==d)
		{
			cout<<flag[c][d]<<endl;
			return 0;
		}
		for(int i=1;i<=k;i++) 
		{
			if(cek(x,y-i)&&flag[x][y-i]==0&&arr[x][y-i]!='@') flag[x][y-i]=z+1,q.push({{x,y-i},z+1});
			else if(!cek(x,y-i)||arr[x][y-i]=='@'||flag[x][y-i]<=z) break;
		}
		for(int i=1;i<=k;i++) 
		{
			if(cek(x+i,y)&&flag[x+i][y]==0&&arr[x+i][y]!='@') flag[x+i][y]=z+1,q.push({{x+i,y},z+1});
			else if(!cek(x+i,y)||arr[x+i][y]=='@'||flag[x+i][y]<=z) break;
		}
		for(int i=1;i<=k;i++) 
		{
			if(cek(x,y+i)&&flag[x][y+i]==0&&arr[x][y+i]!='@') flag[x][y+i]=z+1,q.push({{x,y+i},z+1});
			else if(!cek(x,y+i)||arr[x][y+i]=='@'||flag[x][y+i]<=z)break;
		}
		for(int i=1;i<=k;i++) 
		{
			if(cek(x-i,y)&&flag[x-i][y]==0&&arr[x-i][y]!='@') flag[x-i][y]=z+1,q.push({{x-i,y},z+1});
			else if(!cek(x-i,y)||arr[x-i][y]=='@'||flag[x-i][y]<=z)break;
		}
	}
	cout<<"-1"<<endl;
}

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

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

  int arr[5][4][11];
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 11; k++) {
	arr[i][j][k] = 0;
      }
    }
  }
  
  int b, f, r, v;
  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    arr[b][f][r] += v;
  }

  for (int i = 1; i < 5; i++) {
    for (int j = 1; j < 4; j++) {
      for (int k = 1; k < 11; k++) {
	cout << " "  << arr[i][j][k];
      }
      cout << endl;
    }
    if (i != 4) cout << "####################" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3068
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let mut x = read::<usize>();
    let y = read::<usize>();
    let mut ans = 0;
    while x <= y {
        ans += 1;
        x = x * 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
class Tree:
    def __init__(self):
        self.root = None
        self.inorder = []
        self.preorder = []

    def insert(self, node):

        p = None
        x = self.root        
        while x is not None:
            p = x
            # print(node.key, x.key)
            if node.key <= x.key:
                x = x.left
            else:
                x = x.right

        # insertするnodeの親を設定
        node.parent = p

        if p is None:
            self.root = node
        else:
            # insertするnodeを親のleftかrightに設定
            if node.key <= p.key:
                # print('leftに設定')
                p.left = node
            else:
                # print('rightに設定')
                p.right = node


    def print_inorder(self):
        self.inorder = []
        self.inorder_traverse(self.root)
        print(' ' + ' '.join(map(str, self.inorder)))

    def print_preorder(self):
        self.preorder = []
        self.preorder_traverse(self.root)
        print(' ' + ' '.join(map(str, self.preorder)))

    def inorder_traverse(self, node):
        if node is None:
            return
        self.inorder_traverse(node.left)
        self.inorder.append(node.key)
        self.inorder_traverse(node.right)

    def preorder_traverse(self, node):
        if node is None:
            return
        self.preorder.append(node.key)
        self.preorder_traverse(node.left)
        self.preorder_traverse(node.right)

tree = Tree()
m = int(input())
for i in range(m):
    line = input().split()
    if line[0] == 'print':
        tree.print_inorder()
        tree.print_preorder()
    elif line[0] == 'insert':
        key = int(line[1])
        tree.insert(Node(key))
    # elif line[0] == 'find':
    #     key = int(line[1])
    #     if tree.find(key):
    #         print('yes')
    #     else:
    #         print('no')
    # elif line[0] == 'delete':
    #     print("current tree----")
    #     print(tree.root.key)
    #     print(tree.root.left.key)
    #     print(tree.root.left.right.key)
    #     print("current tree----")
    #     key = int(line[1])
    #     node = tree.find(key)
    #     tree.delete(node)


Measured memory_bytes: 147764
import java.io.IOException;
import java.io.OutputStream;

public class Main{
	public static void main(String[] args)throws IOException{
		Print p = new Print();
		
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9; j++){
				p.print((i + "x" + j + "=" + i * j + "\n").getBytes());
			}
		}
	}
}

class Print{
	private final OutputStream op = System.out;
	
	public void print(byte buffer[])throws IOException{
		op.write(buffer);
	}
}

Measured memory_bytes: 24212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
ll n,p,a=0;
int main(){
  cin >> n >> p;
  for (size_t i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if(temp%2 == 0)a++;
  }
  ll ans=(a==n?(p!=0?0:pow(2,n)):pow(2,n-1));
  cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
flag = True
if s[0] != 'A':
    flag = False

cnt_second = 0
second = s[2:-1]
for x in second:
    if x == 'C':
        cnt_second += 1

if cnt_second != 1:
    flag = False

cnt_third = 0
for x in s:
    if x.isupper():
        cnt_third += 1

if cnt_third != 2:
    flag = False

print('AC' if flag == True else 'WA')

Measured memory_bytes: 3064
#include <stdio.h>

int
main()
{
    int n, i, x;
    int maxv, minv;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (i == 0) {
            minv = x;
            continue;
        }

        if (i == 1) {
            maxv = x - minv;
            if (minv > x)
                minv = x;
            continue;
        }

        if (maxv < (x - minv))
            maxv = x - minv;

        if (minv > x)
            minv = x;
    }
    printf("%d\n", maxv);
    return 0;
}


Measured memory_bytes: 2092
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int N;
int a[100100];
int b[100100];
vector<int>G[100100];
map<pii, int>mp;
int res = 0;
void dfs(int x, int p,int col) {
	for (int a : G[x]) {
		if (a == p)continue;
		col++;
		col %= res;
		int A = x, B = a;
		if (A > B)swap(A, B);
		mp[{A, B}] = col;
		dfs(a, x, col);
	}
}
int main() {
	cin >> N;
	REP(i, N-1) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	int idx = 0;
	REP(i, N) {
		if ((int)G[i].size() > res) {
			res = G[i].size();
			idx = i;
		}
	}
	cout << res << endl;
	dfs(idx,-1,0);
	REP(i, N-1) {
		cout << mp[{a[i], b[i]}]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main(int argc,char *argv[]){
	cin >> a >> b;
	if(b < a) swap(a,b);
	if((b - a) & 1)	cout << "IMPOSSIBLE";
	else	cout << b - (b - a) / 2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
typedef long long ll;
typedef std::pair<int,int> pii;
#define lson rt<<1
#define rson rt<<1|1
#define clr(a,x) memset(a,x,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(int)(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(int)(b);--i)
#define EFOR(i,u) for(int i=lnk[u];i;i=nxt[i])
#define DEBUG(x) std::cerr<<#x<<" = "<<x<<'\n'
const int inf=1<<30;
const long long INF=1LL<<61;
void judge() {
#ifdef SIYUAN
	freopen("in.txt","r",stdin);
#endif
}
inline char nc() {
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;bool neg=0;char c=nc();for(;c<'0'||c>'9';neg|=(c=='-'),c=nc());
	for(;c>='0'&&c<='9';s=10*s+(c^48),c=nc());neg&&(s=-s);
}
int pow(int x,int p,int mod) {
	int res=1;
	for(;p;p>>=1,x=1LL*x*x%mod) if(p&1) res=1LL*res*x%mod;
	return res;
}
int gcd(int x,int y) {return y?gcd(y,x%y):x;}

using namespace std;
const int mod=1e9+7;
int n,m,k,tot,msk[10005],f[105][55][12];
void dfs(int dep,int s) {
	if(dep>=m) {
		msk[++tot]=s;
		return;
	}
	dfs(dep+1,s);
	dfs(dep+2,s|1<<(dep-1));
}
void upd(int &x,int y) {(x+=y)>=mod&&(x-=mod);}
int main() {
//	judge();
	cin>>n>>m>>k;
	dfs(1,0);
//	printf("%d\n",tot);
	for(int i=1;i<=tot;++i) {
		if(msk[i]&1) f[1][i][2]=1;
		else f[1][i][1]=1;
	}
	FOR(i,2,n) {
		FOR(now,1,tot) {
			FOR(lst,1,tot) {
				FOR(ed,1,m) {
					if(ed>1&&msk[now]&(1<<(ed-2))) upd(f[i][now][ed-1],f[i-1][lst][ed]);
					else if(msk[now]&(1<<(ed-1))) upd(f[i][now][ed+1],f[i-1][lst][ed]);
					else upd(f[i][now][ed],f[i-1][lst][ed]);
				}
			}
		}
	}
	int ans=0;
	FOR(i,1,tot) upd(ans,f[n][i][k]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
// AOJ DPL_2_A Traveling Salesman Problem
// 2018.5.5 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF 0x03030303

#define MAX_V  16
int dp[1<<MAX_V][MAX_V];
int d[MAX_V][MAX_V];

int traveling_salesman(int V)
{
	int s, u, v, x;

	memset(dp, INF, sizeof(dp));
	dp[(1<<V)-1][0] = 0;
	for (s = (1<<V)-2; s >= 0; s--) {
		for (v = 0; v < V; v++) {
			for (u = 0; u < V; u++) if (d[v][u] < INF) {
				if ((s>>u) & 1) continue;
				x = dp[s | (1<<u)][u] + d[v][u];
				if (x < dp[s][v]) dp[s][v] = x;
			}
		}
	}
	return dp[0][0];
}

int main()
{
	int V, E, ans;

	memset(d, INF, sizeof(d));
	V = in(), E = in();
	if (!E) { puts("-1"); return 0; }

	while (E--) {
		int s = in(), t = in();
		d[s][t] = in();
	}
	ans = traveling_salesman(V);
	if (ans >= INF) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5944
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    int n = -1;
    int x = -1;

    while (true) {
        int count = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        FORN(i, 1, n) {
            FORN(j, i + 1, n) {
                FORN(k, j + 1, n) {
                    if (i + j + k == x) count++;
                }
            }
        }
        P(count);
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define forn(i, n) for(int i=0;i<(n);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
	ll k, q; cin >> k >> q;
	vll d(k); forn(i, k) cin >> d[i];
	while(q--) {
		ll n, x, m; cin >> n >> x >> m;
		ll ans = n-1;
		n--; // 0~n-1
		// (aj mod m) = (aj+1 mod m)
		ll p1 = 0; // period1
		for(ll i=0;i<k;i++) if(d[i]%m == 0) p1++;
		ans -= p1 * (n/k);
		for(ll i=0;i<n%k;i++) if(d[i]%m == 0) ans--;
		
		// (aj mod m) > (aj+1 mod m)
		// quotient : an-1/m - a0/m
		ll q=0, r=x%m; // quotient, remainder
		ll pq=0, pr=0; // preiod q, period r
		for(ll i=0;i<k;i++) {
			pr += d[i]%m;
			pq += pr/m; pr = pr%m;
		}
		
		q += pq*(n/k); r += pr*(n/k);
		q += r/m; r = r%m;
		
		for(ll i=0;i<n%k;i++) {
			r += d[i]%m;
			q += r/m; r = r%m;
		}
		
		ans -= q;
		cout << ans << endl;
	}
}

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

int N, A[200000];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (A[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	long long ans = 0;
	int now_height = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (A[i] < now_height) {
			cout << -1 << endl;
			return 0;
		}
		if (A[i] > now_height) {
			ans += A[i];
			now_height = A[i];
		}
		if (now_height > 0) {
			now_height--;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
    
    int x,y;
    
    while (1) {
        std::cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x > y){
            int temp = 0;
            temp = x;
            x = y;
            y = temp;
        }
        std::cout << x << " " << y << "\n";
    }
        
    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  V[s] = true;
  while ( !q.empty() ) {
    int u = q.front(); q.pop();
    out.push_back(u);
    for ( int i = 0; i < G[u].size(); i++ ) {
      int v = G[u][i];
      indeg[v]--;
      if ( indeg[v] == 0 && !V[v] ) {
        V[v] = true;
        q.push(v);
      }
    }
  }
}

void tsort() {
  for ( int i = 0; i < N; i++ )
    indeg[i] = 0;

  for ( int u = 0; u < N; u++ )
    for ( int i = 0; i < G[u].size(); i++ ) {
      int v = G[u][i];
      indeg[v]++;
    }

  for ( int u = 0; u < N; u++ )
    if ( indeg[u] == 0 && !V[u] ) bfs(u);

  for ( list<int>::iterator it = out.begin(); it != out.end(); it++ )
    cout << *it << endl;
}

int main() {
  int s, t, M;

  cin >> N >> M;

  for ( int i = 0; i < N; i++ ) V[i] = false;

  for ( int i = 0; i < M; i++ ) {
    cin >> s >> t;
    G[s].push_back(t);
  }

  tsort();

  return 0;
}


Measured memory_bytes: 6232
from collections import deque

H,W = map(int,input().split()) 
A = [[0]*W for _ in range(H)]
M = 0
queue = deque()
for i in range(H):
  s = input()
  for j in range(W):
    if s[j]== '#':
      queue.append([i,j,0])
      A[i][j] = '#'
while queue:
  i,j,cost = queue.popleft()
  M=max(M,cost)
  if i+1 < H and A[i+1][j] != '#':
    queue.append([i+1,j,cost+1])
    A[i+1][j] = '#'
  if i-1 >= 0 and A[i-1][j] != '#':
    queue.append([i-1,j,cost+1])
    A[i-1][j] = '#'
  if j+1 < W and A[i][j+1] != '#':
    queue.append([i,j+1,cost+1])
    A[i][j+1] = '#'
  if j-1 >= 0 and A[i][j-1] != '#':
    queue.append([i,j-1,cost+1])
    A[i][j-1] = '#'
print(M)
    

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,M;
  cin >> N >> M;
  vector<ll> v(N);
  map<int,ll> m;
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
    v.at(i) %= M;

    if(i > 0){
      v.at(i) += v.at(i-1);
      v.at(i) %= M;
    }

    if(m.count(v.at(i)) == 0){
      m[v.at(i)] = 1;
    } else { 
      m[v.at(i)]++;
    }
  }

  ll ans = 0;
  for(auto x: m){
    if(x.first == 0){
      ans += x.second;
    }

    ans += x.second * (x.second -1) / 2;

  }
  cout << ans << endl;

}


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

int N;
int mem[10] = {0};
int ans = 0;
int sum = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        if(a >= 3200)
        {
            sum++;
        }
        else if(mem[a / 400] == 0)
        {
            ans++;
            mem[a / 400] = 1;
        }
    }
    printf("%d %d\n",max(ans,1),ans + sum);
    return 0;
}


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

int main() {
  int N, c=0, bo=1;
  cin >> N;
  
  vector<int> v(N);
  for(int i=0;i < N;i++){
    cin >> v.at(i);
  }
  
  while(true){
    if(bo == 2){
      cout << c << endl;
      break;
    }else{
      if(c >= N){
        cout << -1 << endl;
        break;
      }
      bo=v.at(bo-1);
      c++;
    }
  }
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
N, Q = map(int, input().split())
to = [[] for _ in range(N)]
ans = [0 for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

dfs(0, -1)
print(*ans)

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

struct L {
  int a, b, c;
  L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<L> lh(n), lv(m);
  map<int, int> mpx, mpy; //その座標が何番目か
  mpx[0] = 0, mpy[0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    lh[i] = L(a, b, c);
    mpx[a] = 0, mpx[b] = 0, mpy[c] = 0;
  }
  rep(i, m) {
    int a, b, c;
    cin >> c >> a >> b;
    L l(a, b, c);
    lv[i] = L(a, b, c);
    mpy[a] = 0, mpy[b] = 0, mpx[c] = 0;
  }
  vector<int> xs, ys; //i番目の座標
  for (auto &it : mpx) {
    it.second = xs.size();
    xs.push_back(it.first);
  }
  for (auto &it : mpy) {
    it.second = ys.size();
    ys.push_back(it.first);
  }
  int w = xs.size() * 2, h = ys.size() * 2;
  vector<vector<int>> board(h, vector<int>(w));
  for (auto l : lh) {
    for (int i = mpx[l.a] * 2; i <= mpx[l.b] * 2; i++)
      board[mpy[l.c] * 2][i] = -1;
  }
  for (auto l : lv) {
    for (int i = mpy[l.a] * 2; i <= mpy[l.b] * 2; i++)
      board[i][mpx[l.c] * 2] = -1;
  }
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, 1, 0, -1};
  int x = mpx[0] * 2, y = mpy[0] * 2;
  board[y][x] = 1;
  queue<pair<int, int>> visit;
  visit.push(make_pair(x, y));
  bool inf = false;
  while (!visit.empty()) {
    x = visit.front().first, y = visit.front().second;
    visit.pop();
    if (x <= 0 || w - 1 <= x || y <= 0 || h - 1 <= y) {
      inf = true;
      break;
    }
    rep(i, 4) {
      int xx = x + dx[i], yy = y + dy[i];
      if (board[yy][xx] == 1 || board[yy][xx] == -1) continue;
      board[yy][xx] = 1;
      visit.push(make_pair(xx, yy));
    }
  }
  if (inf) {
    cout << "INF" << endl;
    return 0;
  }
  ll sum = 0;
  for (int j = 1; j < h; j += 2) {
    for (int i = 1; i < w; i += 2) {
      if (board[j][i] == 1) {
        sum += (ll)(xs[(i + 1) / 2] - xs[(i - 1) / 2]) * (ll)(ys[(j + 1) / 2] - ys[(j - 1) / 2]);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 144448
def main():

    H, W, A, B = map(int, input().split())
    isfound = False
    for m in range(H+1):
        for n in range(W+1):
            if m*A + (H-m)*(W-A) == n*B + (W-n)*(H-B):
                isfound = True
                p, q = m, n
                break
        if isfound:
            break
    if not isfound:
        return "No"

    count = [B for _ in range(q)] + [H-B for _ in range(W-q)]

    for i in range(p):
        temp = []
        cnt = A
        for j in range(W):
            if count[j] > 0 and cnt > 0:
                cnt -= 1
                count[j] -= 1
                temp.append(1)
            else:
                temp.append(0)
        print("".join(map(str, temp)))

    for i in range(H-p):
        temp = []
        cnt = W-A
        for j in range(W):
            if count[j] > 0 and cnt > 0:
                cnt -= 1
                count[j] -= 1
                temp.append(1)
            else:
                temp.append(0)
        print("".join(map(str, temp)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 4084
#include <stdio.h>

int main() {
	int M1, D1,M2,D2;
	scanf("%d%d", &M1,&D1);
	scanf("%d%d", &M2,&D2);
	if (M1 == M2) {
		printf("0");
	}
	else {
		printf("1");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
using namespace std;
#define PB push_back
typedef long long int ll;
constexpr int kN = int(1E5 + 10), kMod = int(1E9 + 7);
vector<int> graph[kN];
ll dp[kN][2];
void dfs(int pos, int from = 1) {
	for (int i : graph[pos]) if (i != from) dfs(i, pos);
	dp[pos][0] = dp[pos][1] = 1;
	for (int i : graph[pos]) if (i != from) {
		dp[pos][0] = dp[pos][0] * (dp[i][0] + dp[i][1]) % kMod;
		dp[pos][1] = dp[pos][1] * dp[i][0] % kMod;
	}
	return ;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 2, l, r; i <= n; i++) {
		scanf("%d%d", &l, &r);
		graph[l].PB(r);
		graph[r].PB(l);
	}
	dfs(1);
	printf("%lld\n", (dp[1][0] + dp[1][1]) % kMod);
}


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}






int main(void){
    long long n, m;
    long long ans = 0;
    scanf("%lld %lld", &n, &m);
    if (m - 2*n >= 0){
        m -= 2*n; 
        ans = n;
        n = 0;
    }else{
        ans = m/2;
        printf("%lld\n", ans);
        return 0;
    }
    ans += m/4;
    printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

using namespace std;

#define MIN(a, b) a < b ? a : b

int main()
{
	unsigned long long M,N;
	string s;

	cin >> N;
	cin >> s;

	for(int i = 0; i < 4; i++)
	{
		const int SHEEP = 0;
		const int WOLF  = 1;
		char start = s[0];
		bool clear = true;
		vector<int> answer;
		for(int j = 1; j < s.length()-1; j++)
		{
			answer.resize(s.length(), 0);
			answer[0] = i & 1;
			answer[1] = i / 2;
		
			if((s[j] == 'o' && answer[j] == SHEEP) 
				|| s[j] == 'x' && answer[j] == WOLF)
			{
				answer[j+1] = answer[j-1];
			}
			else
			{
				answer[j+1] = 1 - answer[j-1];
			}
		}

		bool check = true;
		if(s[0] == 'o')
		{
			if(answer[0] == SHEEP && (answer[s.length()-1] != answer[1])) check = false;
			if(answer[0] == WOLF && (answer[s.length()-1] == answer[1])) check = false;
		}
		else
		{
			if(answer[0] == WOLF && (answer[s.length()-1] != answer[1])) check = false;
			if(answer[0] == SHEEP && (answer[s.length()-1] == answer[1])) check = false;
		}

		if(s[s.length()-1] == 'o')
		{
			if(answer[s.length()-1] == SHEEP && (answer[s.length()-2] != answer[0])) check = false;
			if(answer[s.length()-1] == WOLF && (answer[s.length()-2] == answer[0])) check = false;
		}
		else
		{
			if(answer[s.length()-1] == WOLF && (answer[s.length()-2] != answer[0])) check = false;
			if(answer[s.length()-1] == SHEEP && (answer[s.length()-2] == answer[0])) check = false;
		}

		if(check)
		{
			string sAns;
			for(int j = 0; j < s.length(); j++)
			{
				sAns.push_back(answer[j] ? 'W' : 'S');
			}

			cout << sAns << endl;
			return 0;
		}
	}


	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1052
'use strict'

const main = input => {
	const args = input.trim().split('\n')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	const h = parseInt(args[2], 10)
	console.log((a + b) * h / 2)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
from itertools import permutations

n = int(input())
q = [list(map(int, input().split())) for _ in range(n)]
for p in permutations(range(8), 8):
    if all(p[i] == j for i, j in q):
        m = [["."] * 8 for _ in range(8)]
        for i, j in enumerate(p):
            m[i][j] = "Q"
        b = True
        for i, j in enumerate(p):
            for k in range(1, 8):
                if 0 <= i + k < 8 and 0 <= j + k < 8:
                    if m[i + k][j + k] == "Q":
                        break
                if 0 <= i - k < 8 and 0 <= j + k < 8:
                    if m[i - k][j + k] == "Q":
                        break
                if 0 <= i + k < 8 and 0 <= j - k < 8:
                    if m[i + k][j - k] == "Q":
                        break
                if 0 <= i - k < 8 and 0 <= j - k < 8:
                    if m[i - k][j - k] == "Q":
                        break
            else:
                continue
            b = False
            break
        if b:
            for a in m:
                print(*a, sep="")
            exit()



Measured memory_bytes: 5668
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a[15],b[15];
bool one[15];
bool w[15];
int ans=1e9;
main()
{
	cin>>n>>m;
	int sum=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)sum+=a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<m;i+=2)one[i]=1;
	int now=0;
	for(int i=0;i<m;i++)now+=one[i]*b[i];
	if(sum==now)
	{
		int asdf=0;
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<b[i];j++)w[asdf++]=one[i];
		}
		int aans=0;
		int f=0;
		for(int i=0;i<n;i++)
		{
			if(!w[i])continue;
			while(a[f]==0)f++;
			aans+=abs(f-i);
			f++;
		}
		ans=min(ans,aans);
	}
	for(int i=0;i<m;i++)one[i]=0;
	for(int i=1;i<m;i+=2)one[i]=1;
	now=0;
	for(int i=0;i<m;i++)now+=one[i]*b[i];
	if(sum==now)
	{
		int asdf=0;
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<b[i];j++)w[asdf++]=one[i];
		}
		int aans=0;
		int f=0;
		for(int i=0;i<n;i++)
		{
			if(!w[i])continue;
			while(a[f]==0)f++;
			aans+=abs(f-i);
			f++;
		}
		ans=min(ans,aans);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3108
N=input()
N=int(N)
d = [0 for i in range(N)]
for i in range(N):
    d[i]=input()
    d[i]=int(d[i])

#処理
count=0
now=101
#最大値を探し、現状よりも小さいか判定
for i in range(N):
    temp=max(d)
    if temp<now:
        count+=1
        now=temp
    d[d.index(max(d))]=0

print(count)

Measured memory_bytes: 3064
import collections
import itertools
import sys

def getint(): return int(input())
def getints(): return list(map(int, input().split()))


class Graph:
    def __init__(self, node_count, edge_count):
        self.lst = [-1 for _ in range(node_count)]
        self.nxt = [0  for _ in range(edge_count)]
        self.to  = [0  for _ in range(edge_count)]
        self.m   =  0

    def add_edge(self, u, v, w):  # bidirection weight
        m = self.m
        self.nxt[m], self.lst[u], self.to[m]= self.lst[u], m, (v, w)
        self.m += 1

    def traverse(self,u):
        m = self.lst[u]
        while m != -1:
            yield self.to[m]
            m = self.nxt[m]

n,m=getints()
graph = Graph(n,2*m)
for i in range(m):
    a,b=getints()
    graph.add_edge(a-1,b-1,1)
    graph.add_edge(b-1,a-1,1)

visited = [False] * n

def solve(u, visited):
    if visited[u]:
        return 0
    visited[u]=True
    if all(visited):
        visited[u]=False
        return 1
    res = 0
    for v,_ in graph.traverse(u):
        res += solve(v, visited)
    visited[u]=False
    return res

print(solve(0, visited))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    int a,b,c;
    cin>>a>>b>>c;

    if(a+b==c||a+c==b||b+c==a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

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

  int res = 700;
  rep(i, S.size()) {
    if (S[i] == 'o') res += 100;
  }

  cout << res << endl;
}

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

bool eularCheck(vector<int> degree) {
	bool flag = true;
	if (degree[1] % 2 == 0 or degree[2] % 2 == 0) flag = false;
	for (int i = 3; i < degree.size(); ++i) {
		if (degree[i] % 2 == 1) flag = false;
	}
	return flag;
}



signed main() {
	int a, b;
	vector<int> degree(110);

	while (cin >> a >> b) {
		degree[a]++;
		degree[b]++;
		if (a == 0) {
			if (eularCheck(degree)) {
				cout << "OK" << endl;
			}
			else {
				cout << "NG" << endl;
			}
			for (int i = 0; i < degree.size(); ++i) {
				degree[i] = 0;
			}
		}
	}
}



Measured memory_bytes: 3112
//Written by Rhitwik Saha//
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vb          vector<bool>
#define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define ub(x)       upper_bound(x)
#define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N 			1e5+5
#define M           1000000007
#define MAX         100005
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
int i,j,k;

void Anon_mouS(){
	int h, w;
	cin >> h >> w;
	if(h == 1 or w == 1)
		cout << 1 << endl;
	else{int p = (h*w+1)/2;
	cout << p << endl;}
}

int32_t main(){
    fastio;
    // file;
    // sieve();
    int q=1;
    // cin>>q;
    while(q--)Anon_mouS();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>

using namespace std;

#define endl '\n'

const int mod = 998244353;

int modexp(int a, int n)
{
    int b = 1;

    while (n)
    {
        if (n & 1)
        {
            b = 1LL * a * b % mod;
        }

        n >>= 1;
        a = 1LL * a * a % mod;
    }
    return b;
}

void add(int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

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

    int t18 = modexp(10, 18);

    int n;
    cin >> n;

    vector<int> p18(n + 1);
    p18[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        p18[i] = 1LL * p18[i - 1] * t18 % mod;
    }

    vector<int> grundy(1, 1);

    for (int i = 0; i < 3; ++i)
    {
        int m;
        cin >> m;

        vector<vector<int>> adj(n);

        for (int j = 0; j < m; ++j)
        {
            int u, v;
            cin >> u >> v;
            u--;
            v--;
            if (u > v)
                swap(u, v);
            adj[u].push_back(v);
        }

        vector<int> c_grundy(n);
        vector<int> n_grundy;

        int one = 0, zero = 0;

        for (int j = n - 1; j >= 0; --j)
        {
            set<int> s;
            for (auto u : adj[j])
                s.insert(c_grundy[u]);

            int g = 0;
            while (s.count(g))
                g++;

            c_grundy[j] = g;
            while (n_grundy.size() <= g)
                n_grundy.push_back(0);
            add(n_grundy[g], p18[j + 1]);
        }

        vector<int> a_grundy;

        for (int u = 0; u < grundy.size(); ++u)
        {
            for (int v = 0; v < n_grundy.size(); ++v)
            {
                int t = u ^ v;
                while (a_grundy.size() <= t)
                    a_grundy.push_back(0);

                add(a_grundy[t], 1LL * grundy[u] * n_grundy[v] % mod);
            }
        }

        grundy.swap(a_grundy);
    }

    cout << grundy[0] << endl;

    return 0;
}

Measured memory_bytes: 5248
//Tree Walk
#include <iostream>

using namespace std;

static const int NIL = -1;

struct Node {
    int parent = NIL, left = NIL, right = NIL;
};

void preOrder(Node N[], int r) {
    cout << " " << r;
    if(N[r].left != NIL) preOrder(N, N[r].left);
    if(N[r].right != NIL) preOrder(N, N[r].right);
}

void inOrder(Node N[], int r) {
    if(N[r].left != NIL) inOrder(N, N[r].left);
    cout << " " << r;
    if(N[r].right != NIL) inOrder(N, N[r].right);
}

void postOrder(Node N[], int r) {
    if(N[r].left != NIL) postOrder(N, N[r].left);
    if(N[r].right != NIL) postOrder(N, N[r].right);
    cout << " " << r;
}


int main() {
    int n, id, left, right;
    cin >> n;
    Node N[n];
    for(int i=0; i<n; i++) {
        cin >> id >> left >> right;
        if (left != NIL) {
            N[id].left = left;
            N[left].parent = id;
        }
        if (right != NIL) {
            N[id].right = right;
            N[right].parent = id;
        }
    }

    int r;
    for(int i=0; i<n; i++) {
        if(N[i].parent == NIL) {
            r = i; break;
        }
    }

    cout << "Preorder" << endl;
    preOrder(N, r);
    cout << endl;
    cout << "Inorder" << endl;
    inOrder(N, r);
    cout << endl;
    cout << "Postorder" << endl;
    postOrder(N, r);
    cout << endl;
}



Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N, W, v[101], w[101], dp[101][10001];
    cin>>N>>W;
    for (int i=1; i<=N; i++) cin>>v[i]>>w[i];
    for (int i=0; i<10001; i++) dp[0][i]=0;
    for (int i=1; i<=N; i++)
    {
        for (int j=0; j<=W; j++)
        {
            if (w[i]>j) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout<<dp[N][W]<<'\n';
    return 0;
}



Measured memory_bytes: 7044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

int main()
{
    int N;

    cin >> N;

    vector<int> v, p(N), q(N);
    for(int i = 0;i < N;i++)cin >> p[i];
    for(int i = 0;i < N;i++)cin >> q[i];
    for(int i = 1;i <= N;i++)v.push_back(i);
    int np, nq;
    int c = 1;
    do
    {
        if(v == p )np = c;
        if(v == q )nq = c;
        c++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(np-nq) << endl;

    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N; cin>>N;
    int xp=0,yp=0,tp=0;
    int xn,yn,tn;
    REP(i,N) {
        cin>>tn>>xn>>yn;
        int td = tn-tp;
        int xd = abs(xn-xp);
        int yd = abs(yn-yp);
        if (td<xd+yd || (td-xd-yd)%2) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int A[n] = {};
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int tmp = A[0];
    for(int i = 0; i < n; i++){
        if(tmp == 2){
            cout << i+1 << endl;
            return 0;
        }
        tmp = A[tmp-1];
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 640