akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

struct Edge{
    int to, cap, rev;
    Edge(int t, int c, int r):to(t), cap(c), rev(r) {}
};

void AddEdge(int fr, int to, int cap, vector<vector<Edge> >& gr)
{
    gr[fr].push_back( Edge(to, cap, gr[to].size()) );
    gr[to].push_back( Edge(fr, 0, gr[fr].size()-1) );
}

int dfs(int v, int G, int f, vector<vector<Edge> >& gr, vector<int>& used )
{
    if(v==G) return f;
    used[v]=1;
    auto it = gr[v].begin();
    for(; it!=gr[v].end(); ++it) {
        if(!used[it->to] && it->cap>0) {
            int d = dfs( it->to, G, MIN(f, it->cap), gr, used);
            if(d>0) {
                it->cap -= d;
                gr[it->to][it->rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow( int S, int G, vector<vector<Edge> >& g)
{
    int flow=0;
    while(1) {
        vector<int> used(g.size(), 0);
        int f = dfs(S, G, INF, g, used);
        if(f==0) break;
        flow += f;
    }
    return flow;
}


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<vector<Edge> > gr(n*2+2);
    vector<int> a(n),b(n),c(n),d(n);

    int S=n*2;
    int G=n*2+1;
    int i;
    for(i=0; i<n; i++) {
        scanf("%d%d", &a[i], &b[i]);
        AddEdge(S, i, 1, gr);
    }
    for(i=0; i<n; i++) {
        scanf("%d%d", &c[i], &d[i]);
        AddEdge(n+i, G, 1, gr);
    }
    
    int j;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if(a[i]<c[j] && b[i]<d[j]) {
                AddEdge(i, n+j, 1, gr);
            }
        }
    }

    int f=max_flow(S, G, gr);
    printf("%d\n", f);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
    int n,i=3;
	scanf("%d",&n);
    while (i<=n) {
        if(i%3==0){
			printf(" %d",i);
    	}
		else{
			int temp = i;
			while(temp >0){
				if(temp%10==3){
					printf(" %d",i);
					temp = 0;	
				}
				temp = temp / 10;
			}
    	}
		i++;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		int N=sc.nextInt();
		int T=sc.nextInt();
		
		int tt[]=new int[N+1];
		tt[0]=0;
		long sum=0;
		for(int i=1;i<=N;i++) {
			tt[i]=sc.nextInt();
			
			sum+=Math.min(tt[i]-tt[i-1], T);
			
		}
		p(sum+T);
		
		
		
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 64804
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string> v;
  FOR(i,0,1000000){
    string s;
      cin>>s;
      v.push_back(s);
      if(v[i][0]=='=') break;
  }
  int ans = stoi(v[0]);
  int n = v.size();
  FOR(i,1,n-1){
    if(v[i][0]=='+'){
        ans += stoi(v[i+1]);
        i++;
    }
    if(v[i][0]=='-'){
        ans -= stoi(v[i+1]);
        i++;
    }
    if(v[i][0]=='/'){
        ans /= stoi(v[i+1]);
        i++;
    }
    if(v[i][0]=='*'){
        ans *= stoi(v[i+1]);
        i++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3196
s = input()
if len(s) > 9:
    print('NO')
elif s == 'AKIHABARA' or \
     s == 'AKIHABAR' or \
     s == 'AKIHABRA' or \
     s == 'AKIHBARA' or \
     s == 'KIHABARA' or \
     s == 'AKIHABR' or \
     s == 'AKIHBAR' or \
     s == 'KIHABAR' or \
     s == 'AKIHBRA' or \
     s == 'KIHABRA' or \
     s == 'KIHBARA' or \
     s == 'AKIHBR' or \
     s == 'KIHBRA' or \
     s == 'KIHABR' or \
     s == 'KIHBAR' or \
     s == 'KIHBR':
    print('YES')
else:
    print('NO')



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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 1000; i++) {
		int cur = i + 1000;
		for (int j = s.size() - 1; cur > 1 && j >= 0; j--) {
			if (s[j] - '0' == cur % 10) {
				cur /= 10;
			}
		}
		if (cur == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
package main
import "fmt"
func main() {
  var N,M,X int
  fmt.Scan(&N,&M,&X)
  A := make([]int,M)
  right :=0
  for i:=0;i<M;i++{
    fmt.Scan(&A[i])
    if A[i] >= X{
      right += 1
    }
  }
  left := len(A) - right
  if left < right{
    fmt.Println(left)
  }else{
    fmt.Println(right)
  }
}


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

int main() {

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    sort(a.begin(), a.end(), greater<int>());
    if (4 * m * a[m - 1] < sum) { //a[m-1] < sum/(4*m)を調べる。
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;

}


Measured memory_bytes: 256
using System;
 
class Program{
	public static void Main(){
		int w = int.Parse(Console.ReadLine());
		int n = int.Parse(Console.ReadLine());
		int[] m = new int[w];
		while(w-- > 0) m[w] = w+1;
		while(n-- > 0){
            int[] a = Array.ConvertAll(Console.ReadLine().Split(','), int.Parse);
            int b = m[a[0]-1];
			m[a[0]-1] = m[a[1]-1];
			m[a[1]-1] = b;
		}

		foreach(int s in m) Console.WriteLine(s);
	}
}

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

using namespace std;

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

#define ll long long

int main()
{
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      map.put(a, map.getOrDefault(a, 0) + 1);
    }
    PriorityQueue<Integer> pq = new PriorityQueue<>();
    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
      pq.add(entry.getValue());
    }
    int ans = 0;
    while (pq.size() > K) {
      ans += pq.poll();
    }
    
    System.out.println(ans);
  }
}

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

using namespace std;

int main(){
  int n,mod=0,prev=0,dum;
  cin >> n;
  
  while(n--){
    cin >> dum;
    if(dum==prev){
      mod++;
      prev=0;
    }
    else prev=dum;
  }
  cout << mod << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
		var X = input[0];
		var Y = input[1];
		var count = 0;

		while (Y >= X)
		{
			count++;
			X = X * 2;
		}

		Console.WriteLine(count);

	}

}




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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;
vi v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

void solve() {
  int sol = 0, cmax = 0;
  for(int i = 0; i < n; ++i) {
    if (v[i] >= cmax) {
      cmax = v[i];
      ++sol;
    }
  }
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {
        K:usize,
        S:String
    }
    if S.len() > K {
        println!("{}...", &S[0..K]);
    } else {
        println!("{}", S);
    }
}


Measured memory_bytes: 2056
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

int main(void){
  int K, N;
  cin >> N >> K;
  cout << N - K + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int n,m,ans=0;
vector<vector<int>>s(10,vector<int>());
bool used[10];

void dfs(int now,int sum)
{
    used[now]=1;
    if(sum==n)ans++;
    REP(i,s[now].size())if(used[s[now][i]]==0)dfs(s[now][i],sum+1);
    used[now]=0;
}

int main()
{
    cin>>n>>m;
    REP(i,m){int a,b;cin>>a>>b;a--;b--;s[a].push_back(b);s[b].push_back(a);}
    dfs(0,1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);

  int max;
  if(A > B) max = B;
  else max = A;

  int min;
  min = (A + B) - N;
  if(min < 0) min = 0;

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


Measured memory_bytes: 128
n,m = map(int, input().split())
a = [input().split() for i in range(n)]
b = [int(input()) for i in range(m)]

#print(a)
#print(b)

for i in range(n):
    x = 0
    for j in range(m):
        x += int(a[i][j]) * b[j]
    print(x)



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

int main(){
	int debt =100000,n;
	cin >>n;

	while(n--){
		debt = (debt*105)/100;
		if((debt%1000)>0){
			debt += (1000 - debt%1000);
		}
	}

	cout << debt << endl;

    return 0;
}


Measured memory_bytes: 3032
#include <stdio.h>
#include <string.h>

int main(void){
	int N, M, r, t, n, m, s, log[1000][721], q, ts, tg, i, j, k, flag[1000], count;;
	while(1){
		scanf("%d%d",&N,&M);
		if(N == 0 && M == 0)
			break;
		memset(log,0,sizeof(log));
		scanf("%d",&r);
		for(i = 0;i < r;i++){
			scanf("%d%d%d%d",&t,&n,&m,&s);
			if(s == 1)
				log[n - 1][t - 540] = m;
			else if(s == 0)
				log[n - 1][t - 540] = -1;
		}
		memset(flag,0,sizeof(flag));
		for(i = 0;i < N;i++){
			for(j = 0;j <= 720;j++){
				if(log[i][j] && flag[i] == 0)
					flag[i] = log[i][j];
				else if(log[i][j] && flag[i] != 0)
					flag[i] = 0;
				if(flag[i] != 0)
					log[i][j] = flag[i];
			}
		}
		scanf("%d",&q);
		for(i = 0;i < q;i++){
			scanf("%d%d%d",&ts,&tg,&m);
			memset(flag,0,sizeof(flag));
			count = 0;
			for(j = ts - 540;j <= tg - 540;j++){
				for(k = 0;k < N;k++){
					if(flag[k]){
						count++;
						break;
					}
				}
				for(k = 0;k < N;k++){
					if(log[k][j] == m)
						flag[k] = 1;
					else if(log[k][j] != 0)
						flag[k] = 0;
				}
			}
			printf("%d\n",count);
		}
	}
	return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
  string S, T;
  cin >> S >> T;
  int a = 0;
  for (int i = 0; i < S.size(); i++) {
    if (!(S.at(i) == T.at(i))) {
      a = 1;
      break;
    }
  }
  if (a == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
      
      

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h;
  for(int i=0;i<n;i++){
    int temp;
    cin>>temp;
    h.push_back(temp);
  }
  vector<int> minval(n+1,INT_MAX);
  minval[0] = 0;
  for(int i=0;i<n-1;i++){
    for(int j=1;j<=k;j++){
      if(i+j<n)
        minval[i+j] = min(minval[i+j], minval[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<minval[n-1];
}

Measured memory_bytes: 1144
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n, k, c = 0;
	cin >> n >> k;
	int l[n];
	for(int i = 0; i < n; i++){
		cin >> l[i];
	}
	
	sort(l , l + n);
	
	for(int i = n - 1; i > n-k-1; i--){
		c += l[i];
	}
	
	cout << c << endl;
	
 	return 0;
}

Measured memory_bytes: 256
R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
item = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
    r,c,v = map(int,input().split())
    dp1[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)

print(max(dp1[R][C],dp2[R][C],dp3[R][C]))

Measured memory_bytes: 359796
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);

char c = scan.next().charAt(0);
    if(c=='a' || c=='e' || c == 'i' || c =='o' ||c=='u'){
      System.out.println("vowel");
    }else{
      System.out.println("consonant");
    }
    
    
  }
}


Measured memory_bytes: 22740
#include<iostream>
#include<queue>
#include<map>
#include<algorithm>

#define fs first
#define sc second
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int main(){
  int w,h;
  string room[2][50];
  int ry,rx,ly,lx;

  while(cin >> w >> h && (w||h)){
    int ay[2],ax[2];

    for(int i=0;i<h;i++){
      for(int k=0;k<2;k++){
	cin >> room[k][i];
	for(int j=0;j<w;j++){
	  if(room[k][i][j] == 'L'){
	    ly = i; lx = j;
	    room[k][i][j] == '.';
	  }
	  if(room[k][i][j] == 'R'){
	    ry = i; rx = j;
	    room[k][i][j] = '.';
	  }
	  if(room[k][i][j] == '%'){
	    ay[k] = i; ax[k] = j;
	  }
	}
      }
    }

    bool visit[50][50][50][50];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	for(int k=0;k<h;k++)
	  for(int l=0;l<w;l++)visit[i][j][k][l] = false;

    queue<P2> q;
    q.push(P2(P(ly,lx),P(ry,rx)));

    while(q.size()){
      P2 p = q.front();q.pop();
      ly = p.fs.fs; lx = p.fs.sc; ry = p.sc.fs; rx = p.sc.sc;

      if(visit[ly][lx][ry][rx])continue;
      visit[ly][lx][ry][rx] = true;

      if(room[0][ly][lx] == '%' && room[1][ry][rx] == '%')break;

      int ldy[] = {-1,0,1,0}, ldx[] = {0,-1,0,1};
      int rdy[] = {-1,0,1,0}, rdx[] = {0,1,0,-1};

      for(int i=0;i<4;i++){
	int lsy = ly + ldy[i], lsx = lx + ldx[i];
	int rsy = ry + rdy[i], rsx = rx + rdx[i];
	if(lsy < 0 || h-1 < lsy)lsy = ly;
	if(lsx < 0 || w-1 < lsx)lsx = lx;
	if(room[0][lsy][lsx] == '#'){
	  lsy = ly;
	  lsx = lx;
	}
	if(rsy < 0 || h-1 < rsy)rsy = ry;
	if(rsx < 0 || w-1 < rsx)rsx = rx;
	if(room[1][rsy][rsx] == '#'){
	  rsy = ry;
	  rsx = rx;
	}

	if( (room[0][ly][lx] == '%') != (room[1][ry][rx] == '%'))continue;

	q.push(P2(P(lsy,lsx),P(rsy,rsx)));
      }
    }

    if(visit[ay[0]][ax[0]][ay[1]][ax[1]])cout << "Yes\n";
    else cout << "No\n";
  }
}

Measured memory_bytes: 10000
#include<stdio.h>
#include<string.h>
#define min(a,b) ((a)<(b)?(a):(b))
int N,i,j,s,t,C[1001][1001],m,A;
char M[1005][1005];

int main()
{
	for(;scanf("%d\n",&N),N;)
	{
		for(i=0;i<N;i++)
			gets(M[i]);
		for(i=0;i<N;i++)
			for(j=N-1;j>=0;j--)
			{
				if(M[j][i]=='*')C[j][i]=0;
				else if(j==N-1)C[j][i]=1;
				else C[j][i]=C[j+1][i]+1;
			}
		for(i=A=0;i<N;i++)
		{
			for(s=0;s<N;s++)
			{
				for(j=0,m=C[i][s];j<=m;j++)
				{
					if(m>C[i][s+j])
					{
						A=A>min(m,j)?A:min(m,j);
						m=C[i][s+j];
					}
				}
			}
			if(A==N)break;
		}
		printf("%d\n",A);
	}
	return 0;
}

Measured memory_bytes: 5508
s = list(input())
q = int(input())
for _ in range(q):
    line = input().split()
    if line[0][2] == "p":
        s = s[:int(line[1])] + list(line[3]) + s[int(line[2])+1:]
    elif line[0][2] == "v":
        s = s[:int(line[1])] + s[int(line[1]):int(line[2])+1][::-1] + s[int(line[2])+1:]
    elif line[0][0] == "p":
        print("".join(s[int(line[1]):int(line[2])+1]))


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n,k-q);
  rep(i,q){
    int a;
    cin >> a;
    p[a-1]++;
  }
  rep(i,n){
    if(p[i]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll gcds=gcd(a,b);
    if(c%gcds==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}





Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

typedef pair<int,int> p;

int main(void){
   int m;
   p input;
   while(scanf("%d",&m),m){
      vector<p> cons;
      vector<p> stars;
      for(int i = 0;i < m;i++){
         scanf("%d%d",&input.first,&input.second);
         cons.push_back(input);
      }
      int n; scanf("%d",&n);
      for(int i = 0;i < n;i++){
         scanf("%d%d",&input.first,&input.second);
         stars.push_back(input);
      }

      sort(cons.begin(),cons.end());
      sort(stars.begin(),stars.end());
      for(int i = 0;i < n-m;i++){
         int gap_x,gap_y;
         gap_x = stars[i].first - cons[0].first;
         gap_y = stars[i].second - cons[0].second;
         int cnt = 0 ,idx =  0;
         for(int j = i;j < n;j++){
            if(cons[idx].first + gap_x == stars[j].first &&
               cons[idx].second + gap_y == stars[j].second){
                  idx++;
                  cnt++;
                  if(cnt == m) break;
            }
         }
         if(cnt == m){
            printf("%d %d\n",gap_x,gap_y);
            break;
         }
      }
   }
   return 0;
}

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

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int nstone, nplayer;
    cin >> nstone >> nplayer;
    cout << ((nstone % nplayer) ? (nstone % nplayer) : (nplayer)) << endl;
  }
  return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    db l;
    cin >> l;
    cout << fixed << setprecision(12) << (l*l*l)/27 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    long long int A,B,N;

    scanf("%lld %lld %lld", &A,&B,&N);

    if(N >= B-1){
        printf("%lld", ((A*(B-1))/B));
    }else{
        printf("%lld", (A*N)/B);
    }
}

Measured memory_bytes: 1736
package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Color struct {
	name    string
	R, G, B int64
}

func main() {
	colors := []Color{
		{"black", 0, 0, 0},
		{"blue", 0, 0, 0xff},
		{"lime", 0, 0xff, 0},
		{"aqua", 0, 0xff, 0xff},
		{"red", 0xff, 0, 0},
		{"fuchsia", 0xff, 0, 0xff},
		{"yellow", 0xff, 0xff, 0},
		{"white", 0xff, 0xff, 0xff},
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), "")
		if buf[0] == "0" {
			break
		}
		r, _ := strconv.ParseInt(strings.Join(buf[1:3], ""), 16, 64)
		g, _ := strconv.ParseInt(strings.Join(buf[3:5], ""), 16, 64)
		b, _ := strconv.ParseInt(strings.Join(buf[5:], ""), 16, 64)
		vmin := int64(3*0xff*0xff)
		var ans string
		for _, c := range colors {
			d := (r-c.R)*(r-c.R) + (g-c.G)*(g-c.G) + (b-c.B)*(b-c.B)
			if d < vmin {
				vmin = d
				ans = c.name
			}
		}
		fmt.Println(ans)
	}
}



Measured memory_bytes: 1220
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 104, W = (int)1e5 + 10;
ll dp[W], val[N], w[N]; // dp[w] := max value possible of knapsack with weight atmost w till some iteration
int n, cap;

void solve() {
   for (int i = 0; i <= cap; ++i) dp[i] = 0;

   for (int i = 1; i <= n; ++i) {
      for (int j = cap; j >= 1; --j) {
         if (j >= w[i]) dp[j] = max(dp[j], dp[j-w[i]] + val[i]);
      }
   }

   cout << dp[cap] << "\n";
}

signed main() {
   IOS; PREC;
   cin >> n >> cap;
   for (int i = 1; i <= n; ++i) cin >> w[i] >> val[i];
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 1024
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

x = int(input())
print((x//500)*1000 + ((x%500)//5)*5)


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

int main()
{
    int n;
    cin >> n;
    int ar[2][n];
    int sum1[n];
    int sum2[n];
    int sum[n];
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> ar[i][j];
        }
    }
    sum1[0] = ar[0][0];
    sum2[n - 1] = ar[1][n - 1];
    for (int j = 1; j < n; j++)
    {
        sum1[j] = sum1[j - 1] + ar[0][j];
    }
    for (int j = n - 2; j >= 0; j--)
    {
        sum2[j] = sum2[j + 1] + ar[1][j];
    }

    for (int i = 0; i < n; i++)
    {
        sum[i] = sum1[i] + sum2[i];
    }

    sort(sum, sum + n, greater<int>());
    cout << sum[0];
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main
{
    static long prefix[];
    static long dp[][];
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        prefix=new long[str.length+1];
        long arr[]=new long[str.length];
        for(int i=0;i<str.length;i++)
            arr[i]=Long.parseLong(str[i]);
        preprocess(arr);
        dp=new long[arr.length+1][arr.length+1];
        for(int i=0;i<dp.length;i++)
            for(int j=0;j<dp[0].length;j++)
                dp[i][j]=-1;
//        System.out.println(Arrays.toString(prefix));
        System.out.println(calculate(arr,0,arr.length-1));

    }

    private static void preprocess(long arr[]) {
        for(int i=0;i<arr.length;i++)
        {
            prefix[i+1]=prefix[i]+arr[i];
        }

    }

    private static long calculate(long[] arr, int i, int j) {
        if(i==j)
            return 0;
        if(dp[i][j]!=-1)
            return dp[i][j];
        long min=Long.MAX_VALUE;
        long sum=prefix[j+1]-prefix[i];
        for(int k=i;k<j;k++)
        {
            long c1=calculate(arr,i,k);
            long c2=calculate(arr,k+1,j);
            min=Math.min(min,sum+c1+c2);
        }
        return dp[i][j]=min;
    }
}

Measured memory_bytes: 28140
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		int N = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int[] ans = new int[N];
		int index = N / 2;
		int change = (N % 2 == 0 ? -1 : 1);
        for(int i = 0; i < N; i++)
		{
			ans[index] = a[i];
			index += change;
			change = ((change / Math.Abs(change)) + change) * (-1);
		}
        for(var i = 0; i < N; i++)
		{
			Console.Write($"{ans[i]} ");
		}

		Console.Out.Flush();
	}
}


Measured memory_bytes: 40360
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    for(;;){
        int d, n;
        cin >> d >> n;
        if(d == 0)
            return 0;

        vector<int> a(n), e(n), r(n);
        for(int i=0; i<n; ++i)
            cin >> a[i] >> e[i] >> r[i];

        vector<vector<int> > dp(d+1, vector<int>(101, INF));
        dp[0] = vector<int>(101, 0);
        for(int i=1; i<=d; ++i){
            for(int j=100; j>=0; --j){
                for(int k=0; k<n; ++k){
                    if(j < r[k])
                        continue;

                    int i2 = max(0, i - a[k]);
                    int j2 = min(100, j + e[k]);
                    dp[i][j] = min(dp[i][j], dp[i2][j2] + 1);
                }
            }
        }
        if(dp[d][0] < INF)
            cout << dp[d][0] << endl;
        else
            cout << "NA" << endl;
    }
}

Measured memory_bytes: 1264
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

void f(int a,int b){
	cout<<a;
	if(a==b){cout<<endl;return;}
	if(6<=a&&a<=8){
		a++;
	}else if(a==9){
		a=5;
	}else if(a<b){
		a++;
	}else{
		a--;
	}
	cout<<" ";
	f(a,b);
}

int main() {
	int n=in();
	int a,b;
	int i;
	for(i=0;i<n;i++){
		cin>>a>>b;
		if(6<=b&&b<a){
			if(b==6&&a==7)cout<<"7 8 9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==6&&a==8)cout<<"8 9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==6&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==7&&a==8)cout<<"8 9 5 4 3 2 1 0 1 2 3 4 5 6 7"<<endl;
			if(b==7&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6 7"<<endl;
			if(b==8&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6 7 8"<<endl;
		}else{
			f(a,b);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7
const double EPS = 1e-9;

// Vector Type for sorting points by polar angle.
struct V {
  double x, y;

  V(double x = 0, double y = 0) : x(x), y(y) {}

  V& operator+=(const V& v) { x += v.x; y += v.y; return *this; }
  V& operator+(const V& v) const { return V(*this) += v; }
  V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this; }
  V& operator-(const V& v) const { return V(*this) -= v; }
  V& operator*=(double s) { x *= s; y *= s; return *this; }
  V& operator*(double s) const { return V(*this) *= s; }
  V& operator/=(double s) { x /= s; y /= s; return *this; }
  V& operator/(double s) const { return V(*this) /= s; }
  double dot(const V& v) const { return x*v.x + y*v.y; }
  double cross(const V& v) const { return x*v.y - y*v.x; }
  double norm() const { return sqrt(norm2()); }
  double norm2() const { return x*x + y*y; }
  int ort() const { // orchant
    if (abs(x) < EPS && abs(y) < EPS) { return 0; } // Check (0, 0)

    if (y > 0) {
      return (x > 0) ? 1 : 2;
    } else {
      return (x > 0) ? 4 : 3;
    }
  }
  bool operator<(const V& v) const {
    int o = ort();
    int vo = v.ort();
    if (o != vo) { return o < vo; }
    return cross(v) > 0;
  }
};

istream& operator>>(istream& i, V& v) {
  i >> v.x >> v.y;
  return i;
}
ostream& operator<<(ostream& o, const V& v) {
  o << "(" << v.x << ", " << v.y << ")";
  return o;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vector<V> v(N);
  rep(i, N) {
    cin >> v[i];
  }

  sort(all(v));
  double ans = 0;
  rep(i, N) {
    V now(0, 0); // Start from (0, 0)
    rep(j, N) {
      now += v[(i + j) % N];
      ans = max(ans, now.norm());
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  vector<int> v(1000000);
  v[0]=2;
  v[1]=1;
  LOOP(i,2,1000000){
    v[i]  =v[i-1]+v[i-2];
  }
  cout<<v[n]<<endl;
  return 0;
}


Measured memory_bytes: 8064
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for p in range(A + 1):
    for q in range(B + 1):
        for r in range(C + 1):
            if 500 * p + 100 * q + 50 * r == X:
                ans = ans + 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	ll n, a, b, c[11111],i,d[11111],t=0,p[11111],x[11111],ans=0;
	cin >> n;
	vector<int> list[11111];
	priority_queue<pair<int, int>, vector<pair<int,int>>, greater<pair<int,int>>> que;
	for (i = 1; i <= n; i++) {
		d[i] = 0;
		x[i] = 0;
	}
	for (i = 0; i < n-1; i++) {
		cin >> a >> b;
		list[a].push_back(b);
		list[b].push_back(a);
		d[a]++;
		d[b]++;
	}
	for (i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
  for(i=0;i<n-1;i++)
    ans+=c[i];
	for (i = 1; i <= n; i++)
		que.push(make_pair(d[i], i));
	while (!que.empty()) {
		int k1 = que.top().first, k2 = que.top().second;
		if (x[k2]==0) {
			p[k2] = c[t];
			t++;
			x[k2]++;
          que.pop();
			if (t < n) {
				for (const auto& e : list[k2]) {
					if (x[e] == 0) {
						d[e]--;
						que.push(make_pair(d[e], e));
					}
				}
			}
		}
      else
        que.pop();
	}
	cout << ans << endl;
	for (i = 1; i <= n; i++)
		cout << p[i] << " ";
}

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

const int MOD = 1000000007;
const int MAX =200000;

int main() {
  int a, b;
  cin >> a >> b;
  if(a <= 9 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long solve(long X , long K , long D){
		if(X >= 0){
			long ret = X;
			if(X / D >= K){
				return ret - K * D;
			}
			// X < K * D
			long k = X / D;
			ret = X - k * D;
			K -= k;
			if(K % 2 == 0){
				return ret;
			}else{
				return Math.abs(ret - D);
			}
		}else{
			return solve(- X , K , D);
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long K = sc.nextLong();
		long D = sc.nextLong();
		long r = solve(X , K , D);
		
		System.out.println(r);
	}

}


Measured memory_bytes: 35716
{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.List
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IntSet
import qualified Data.IntMap.Strict as IntMap
import Control.Monad

main = do
  [n,m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [x,y,z] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (x-1,y-1,z)
  let tree :: IntMap.IntMap IntSet.IntSet
      tree = U.foldl' (\m (u, v, _) -> IntMap.insertWith IntSet.union u (IntSet.singleton v) $ IntMap.insertWith IntSet.union v (IntSet.singleton u) m) IntMap.empty edges
  vec <- UM.replicate n (-1)
  let find !j
        | j >= n = return Nothing
        | otherwise = do v <- UM.read vec j
                         if v == -1
                           then return (Just j)
                           else find (j+1)
  let dfs !i !value = do
        k <- UM.read vec i
        if k == -1
          then do UM.write vec i value
                  case IntMap.lookup i tree of
                    Just set -> forM_ (IntSet.toList set) $ \j -> dfs j value
                    Nothing -> return ()
          else return ()
  let loop !i = do
        mj <- find i
        case mj of
          Nothing -> return i
          Just j -> do
            dfs j i
            loop (i+1)
  result <- loop 0
  print result


Measured memory_bytes: 42364
#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
	int n;
	while (1) {
		cin >> n;
		int s[1000] = {0};
		if (n == 0)break;
		double sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			sum += s[i];
		}
		double ave = sum / n;
		double ans = 0;
		for (int i = 0; i < n; i++) {
			ans += (s[i] - ave)*(s[i] - ave);
		}
		ans /= n;

		printf("%.8f\n", sqrt(ans));
		
	}
	return 0;

}



Measured memory_bytes: 3128
#include <stdio.h>
#include <stdlib.h>
#define NIL -1
#define RECO -2
typedef struct Node
{
    int parent;
    int firstchild;
    int rightsibling;
}Node;
int CountDepth(Node* List, int ID)
{
    int counter=0;
    while(List[ID].parent!=NIL)
    {
        counter++;
        ID = List[ID].parent;
    }
    return counter;
}
int main() {
    int n, degree, temp, childlist, nodeID, nextsibling=0;
    scanf("%d", &n);
    Node* TreeList =(Node*)malloc(n*sizeof(Node));
    for(int i=0;i<n;i++)
    { TreeList[i].parent=NIL;TreeList[i].firstchild=RECO;TreeList[i].rightsibling=RECO;}
    for(int i=0;i<n;i++)
    {
        scanf("%d %d", &nodeID, &degree);
        for(int j=0;j<degree;j++)
        {
            scanf("%d", &childlist);
            TreeList[childlist].parent = nodeID;
            if(j==0){TreeList[nodeID].firstchild=childlist;}
            else
            {
                TreeList[nextsibling].rightsibling=childlist;
            }
            nextsibling = childlist;
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("node %d: parent = %d, depth = %d,", i, TreeList[i].parent, CountDepth(TreeList, i));
        if(CountDepth(TreeList, i)==0){printf(" root, [");}
        else if(TreeList[i].firstchild==RECO){printf(" leaf, [");}
        else{printf(" internal node, [");}
        if(TreeList[i].firstchild!=RECO)
        {
            printf("%d", TreeList[i].firstchild);
            temp = TreeList[i].firstchild;
            while(TreeList[temp].rightsibling!=RECO)
            {
                printf(", %d", TreeList[temp].rightsibling);
                temp = TreeList[temp].rightsibling;
            }
        }
        printf("]\n");
        
    }
    free(TreeList);
    return 0;
}




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

int main(void){
    int a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f;
    set<int>s;
    for(int i=0;i<30;i++){
        for(int j=0;j<30;j++){
            if(i==j && i==0) continue;
            int water = 100*a*i + 200*b*j;
            if(water <=f)s.insert(water);
        }
    }
    int ans_water=2,ans_sugar=-1;
    for(auto iter=s.begin();iter!=s.end();iter++){
        int water = *iter, max_sugar=min(f-water,water*e/100);
        // cout << water <<' ' << max_sugar << endl;
        for(int i=0;i<=max_sugar/c;i++){
            int sugar = max_sugar - max(0,(max_sugar - i*c)%d);

            if(water+sugar <= f && double(ans_sugar)/(ans_water+ans_sugar) < double(sugar)/(water+sugar)) ans_water = water, ans_sugar = sugar;
        }
    }
    cout << ans_water+ans_sugar << ' ' << ans_sugar << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Array.IO

main = do
        n <- readLn
        list <- map read.words<$>getLine
        arr <- newListArray (0,(n-1)) list
        i <- partition 0 (n-1) arr
        printPartedArray i arr

partition :: Int -> Int -> IOUArray Int Int -> IO Int
partition p r arr = evalStateT (part p r arr) (p-1)

part :: Int -> Int -> IOUArray Int Int -> StateT Int IO Int
part p r arr = do
        x <- liftIO $ readArray arr r
        forM_ [p..(r-1)] $ \j -> do
            e <- liftIO $ readArray arr j
            if e <= x then modify (+1) >> get >>= \i' -> (liftIO $ swap arr i' j)
                      else return ()
        i <- get
        liftIO $ swap arr (i+1) r
        return (i+1)

swap :: IOUArray Int Int -> Int -> Int -> IO ()
swap arr i j = do
        eI <- readArray arr i
        eJ <- readArray arr j
        writeArray arr j eI
        writeArray arr i eJ

printPartedArray :: Int -> IOUArray Int Int -> IO ()
printPartedArray j arr = do
        (s,g) <- getBounds arr
        forM_ [s..g] $ \i -> do
            e <- readArray arr i
            switchCase s g j i e

switchCase s g j i e
    | i == s = putStr $ show e
    | i == g = putStrLn $ " " ++ show e
    | i == j = putStr $ " [" ++ show e ++ "]"
    | otherwise = putStr $ " " ++ show e

Measured memory_bytes: 21476