akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int a[100000];
    for(int i = 0; i < N; ++i) cin >> a[i];
    unordered_map<int, int> m;
    for(int i = 0; i < N; ++i){
        m[a[i]] += 1;
    }
    int cnt = 0;
    for(auto itr = m.begin(); itr != m.end(); ++itr){
        if(itr->first < itr->second){
            cnt += itr->second - itr->first;
        }else if(itr->first > itr->second){
            cnt += itr->second;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4644
// Example program
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long a[n];
  long long b[n];
  long long sum=0;
  for(int i=0;i<n-1;i++)
  {
      cin>>a[i];
      if(i%2)sum+=2*a[i];
      else sum-=2*a[i];
  }
  cin>>a[n-1];
  b[n-1] = (2*a[n-1]+sum)/2;
  b[0] = 2*a[n-1]-b[n-1];
  for(int i=1;i<n-1;i++)
  {
      b[i]=2*a[i-1]-b[i-1];
  }
  for(int i=0;i<n;i++)
  {
      cout<<b[i]<<" ";
  }
}


Measured memory_bytes: 2816
#include <iostream>
#include <math.h>
#include <string>
#pragma warning(disable:4996)
int main()
{
	std::string num;
	std::cin >> num;

	int n_num;
	n_num = stoi(num);

	n_num *= n_num;

	printf("%d",n_num);
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0,A=0,B=0,C=0;
    string X,Y,tmp;

    int ans=0;

    cin>>X>>Y;

    for(int i=0;i<X.size();i++){
        tmp=X[X.size()-1];
        for(int k=0;k<X.size()-1;k++){
            tmp+=X[k];
        }
        X=tmp;

        if(X==Y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			long n = cin.Long();
			List<AB> ab = new List<AB>();
			for (int i = 0; i < n; i++) {
				long a = cin.Long();
				long b = cin.Long();
				ab.Add(new AB { A = a, B = b });
			}

			var ab2 = ab.OrderBy(x => x.B).ToList();
			long[] c = new long[n];
			long sum = 0;
			for (int i = 0; i < n; i++) {
				sum += ab2[i].A;
				if (sum > ab2[i].B) {
					Console.WriteLine("No");
					return;
				}
			}

			Console.WriteLine("Yes");
		}

		public struct AB
		{
			public long A;
			public long B;
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 34228
#include <bits/stdc++.h>
using namespace std;
int x,y;
int main () {
    cin >> x >> y;
    if (x<y && x!=1 && y!=1) {
        cout << "Bob" <<endl;
    }
  
 
    else if (x>y && x!=1 && y!=1) {
        cout << "Alice" <<endl;
    }
        
        
    else if (x==y) {
        cout << "Draw" <<endl;
    }
    
    else if (x==1 && y!=1) {
        cout << "Alice" <<endl;
    }
    
    else if (y==1 && x!=1) {
        cout << "Bob" <<endl;
    }
}

Measured memory_bytes: 3528
n = int(raw_input())
count = 0
res = 0
ais = map(int , raw_input().split())

for i in range(n + 1):
	if (ais[i] if i < n else -1) != i + 1:
		#flush the count
		res += (count + 1)/2# + 1
		count = 0
	else:
		count +=1
print res

Measured memory_bytes: 88148
use std::io::*;
use std::str::FromStr;

pub 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")
}

use std::cmp::min;

fn main() {
    let n = read::<u32>();
    let mut a :Vec<u32> = Vec::new();
    a.push(1);
    let mut ii :u32 = 1;

    while ii * 6 <= n {
        ii *= 6;
        a.push(ii);
    }
    ii = 1;
    while ii * 9 <= n {
        ii *= 9;
        a.push(ii);
    }
    a.sort();

    let mut dp = vec![vec![1000000 as u32; (n+1) as usize]; (a.len()+1) as usize];
    for i in 0..a.len()+1 {
        dp[i][0] = 0;
    }
    for i in 0..a.len() as usize {
        for j in 0..(n+1) as usize {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if j as u32 >= a[i] {
                dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a[i] as usize] + 1);
            }
        }
    }
    println!("{:?}", dp[a.len() as usize][n as usize]);
}

Measured memory_bytes: 10492
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Edge {
	int from, to, cost;

	public Edge(int from, int to, int cost) {
		this.from = from;
		this.to = to;
		this.cost = cost;
	}
}

public class Main {
	static final int SIZE = 2505;
	static final int INF = Integer.MAX_VALUE / 2;
	static List<List<Integer>> to = new ArrayList<>();
	static List<List<Integer>> rto = new ArrayList<>();
	static boolean[] reachableFromI = new boolean[SIZE];
	static boolean[] reachableToN = new boolean[SIZE];
	static boolean[] ok = new boolean[SIZE];

	static void dfs(int v) {
		if (reachableFromI[v]) return;
		reachableFromI[v] = true;
		for (int u : to.get(v)) {
			dfs(u);
		}
	}

	static void rdfs(int v) {
		if (reachableToN[v]) return;
		reachableToN[v] = true;
		for (int u : rto.get(v)) {
			rdfs(u);
		}
	}

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int p = sc.nextInt();
			ArrayList<Edge> edges = new ArrayList<>();
			for (int i = 0; i < SIZE; i++) {
				to.add(new ArrayList<>());
				rto.add(new ArrayList<>());
			}
			for (int i = 0; i < m; i++) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int c = -(sc.nextInt() - p);
				edges.add(new Edge(a, b, c));
				to.get(a).add(b);
				rto.get(b).add(a);
			}
			dfs(0);
			rdfs(n - 1);
			for (int i = 0; i < n; i++) {
				ok[i] = reachableFromI[i] && reachableToN[i];
			}

			int[] d = new int[n];
			Arrays.fill(d, INF);
			d[0] = 0;
			boolean upd = true;
			int step = 0;
			while (upd) {
				upd = false;
				for (int i = 0; i < m; i++) {
					Edge edge = edges.get(i);
					int c = edge.cost;
					if (!ok[edge.from] || !ok[edge.to]) continue;
					int newD = d[edge.from] + c;
					if (newD < d[edge.to]) {
						upd = true;
						d[edge.to] = newD;
					}
				}
				step++;
				if (step > n) {
					System.out.println("-1");
					return;
				}
			}
			int ans = -d[n - 1];
			System.out.println(Math.max(0, ans));
		}
	}
}

Measured memory_bytes: 38440
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_5-A2
Recursion / Divide and Conquer - Exhaustive Search
????????¶??? : 5 sec, ?????¢?????¶??? : 65536 KB
=end

class Main
  def sum(f)
    f.inject(0){|acc,x| acc + x}
  end


  def issum(p, t, f)
    #puts "p=#{p} t=#{t}"
    if t==0 then
      return true
    elsif p==f.length then
      return false
    else

      return issum(p+1,t-f[p], f) || issum(p+1, t, f)
      #return issum(p+1,t-f[p], f) or issum(p+1, t, f)
    end
  end

  def initialize
    #fh=open("/home/muz/Downloads/ALDS1_5_A_in1.txt")
    #fh=open("/home/muz/Downloads/ALDS1_5_A_in10.txt")
    fh=STDIN
    n=fh.gets.chomp.to_i
    f=fh.gets.chomp.split.map{|x| x.to_i}
    q=fh.gets.chomp.to_i
    g=fh.gets.chomp.split.map{|x| x.to_i}
    fh.close
    g.each{|y|
      ans=issum(0, y, f)
      puts  ans ? "yes" : "no"
    }
  end

end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 8676
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())
ll powmod(ll x, ll y) {
	ll res = 1;
	rep(i, y) {
		res *= x;
		res %= MOD;
	}
	return res;
}
int main(void) {
	int n;
	cin >> n;
	ll ans = powmod(10, n) - 2 * powmod(9, n) + powmod(8, n);
	ans    = (ans + 2 * MOD) % MOD;
	cout << ans << endl;
	return 0;
}

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

int H;
const int W = 5;
int fie[11][11];
int res;
bool del(){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int f =  fie[j][i];
      if( f && j+3<=W){
        int cnt = 0;
        for(int k=j; k < W && fie[k][i] == f; k++ )
          cnt++;
        if( cnt > 2 ){
          for(int k=j; k < W && fie[k][i] == f; k++ ){
            res += fie[k][i];
            fie[k][i] = 0;
          }
          return true;
        }
      }
    }
  }
  return false;
}

bool down(){
  bool f = false;
  for(int i=H-1;i>-1;i--){
    for(int j=0;j<W;j++){
      if( fie[j][i] == 0 ){
        fie[j][i] = fie[j][i-1];
        fie[j][i-1] = 0;
        if( fie[j][i] != 0 )
          f= true;
      }
    }
  }
  return f;
}

void view(){
  cout << "view" << endl;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cout << fie[j][i] << " ";
      }     
      cout << endl;
    }
}

void sim(){

  while( del() ){
    while(del());
    while(down());
  }

}

int main(){
  while(cin >> H && H){

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++) cin >> fie[j][i];
    }
    res = 0;
    sim();
    cout << res << endl;
  }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        sc.close();

        int a = n * 800;
        int b = n / 15 * 200;

        System.out.println(a - b);
    }
}

Measured memory_bytes: 21716
def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n,k = gsmi

if k.odd?
	m = n/k
	puts m**3
else
	odd = (n+(k/2))/k
	even = n/k
	puts even**3 + odd**3
end

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

int solve(string s,int left,int right,bool flg){
	int count = 0;

	for(int i=1;i<s.length();i++){
		int next = (s[i] - '1') % 3;

		if(flg){
			if(right < next){
				right = next;
				count++;
			}
			else{
				left = next;
				flg = !flg;
			}
		}
		else{
			if(left > next){
				left = next;
				count++;
			}
			else{
				right = next;
				flg = !flg;
			}
		}
	}

	return count;
}

int main(void){
	string s;

	while(cin>>s && s!="#"){
		int first = (s[0] - '1') % 3;
		cout<<min(solve(s,first,0,false), solve(s,0,first,true))<<endl;
	}

	return 0;
}

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

long long b, a, c;

void solve();
long long ch(long long x, long long y);

int main() {
  while(1) {
    cin >> b;
    if(b == 0) break;
    solve();
    cout << a << " " << c << endl;
  }
  return 0;
}

void solve() {
  a = c = 0;
  for(long long i = 1; i * i <= 2 * b; ++i)
    if(2 * b % i == 0) {
      long long x = ch(2 * b / i, i);
      if(i > c && x > 0) {
        a = x;
        c = i;
      }
      x = ch(i, 2 * b / i);
      if(2 * b / i > c && x > 0) {
        a = x;
        c = 2 * b / i;
      }
    }
}

long long ch(long long x, long long y) {
  x += -y + 1;
  if(x > 0 && x % 2 == 0) return x / 2;
  return -1;
}


Measured memory_bytes: 3064
import heapq;

n, u, v = [int(v) for v in input().split()]

vert = []

for i in range(n):
    vert.append([])

for i in range(n - 1):
    a, b = [int(v) - 1 for v in input().split()]
    vert[a].append(b)
    vert[b].append(a)

taka = u-1
aoki = v-1

if taka == aoki:
    print(0)
    exit()

def bfs(begin):
    q = [(0, begin)]
    dist = [-1] * n
    dist[begin] = 0

    index = 0
    while index < len(q):
        c0, i = q[index]
        c = c0 + 1
        for l in vert[i]:
            if dist[l] >= 0:
                continue
            dist[l] = c
            q.append((c, l))
        index += 1
    return dist

aoki_dist = bfs(aoki)
taka_dist = bfs(taka)

ans = 0
for i in range(n):
    if taka_dist[i] < aoki_dist[i]:
        ans = max(ans, aoki_dist[i] - 1)

print(ans)

Measured memory_bytes: 35784
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l + r < N:
            bag = V[:l] + V[N-r:] + [0]
            rest_ope = K-l-r
        else:
            bag = V[:]
            rest_ope = K - N
        for _ in range(rest_ope):
            min_bag = min(bag)
            if min_bag < 0 and rest_ope > 0:
                bag.remove(min_bag)
                rest_ope -= 1
        else:
            ans = max(ans, sum(bag))

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		while(s.hasNextInt()){
			int n = s.nextInt();
			boolean[] b = new boolean[n*2];
			for(int i = 0;i<b.length;i++){
				b[i] = true;
			}
			b[0] = b[1] = false;
			for(int i = 0;i<b.length;i++){
				if(!b[i])continue;
				for(int j = 2*i;j<b.length;j += i){
					b[j] = false;
				}
			}
			int x = n - 1;
			while(!b[x])x--;
			int y = n + 1;
			while(!b[y])y++;
			System.out.println(x + " " + y);
		}
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {
	class List {
		class Cell {
			Cell prev, next;
			int v;
			Cell(int value) {
				this.v = value;
			}
		}
		Cell cell, lastCell;
		void insert(int value) {
			if (cell == null) {
				cell = new Cell(value);
				lastCell = cell;
				return;
			}
			cell.next = new Cell(value);
			cell.next.prev = cell;
			cell = cell.next;
		}
		void delete(int value) {
			Cell c = cell;
			while (c != null) {
				if (c.v != value) {
					c = c.prev;
					continue;
				}
				Cell prev = c.prev;
				Cell next = c.next;
				if (prev == null && next == null) {
					cell = null;
				} else if (prev == null) {
					next.prev = null;
					lastCell = next;
				} else if (next == null) {
					prev.next = null;
					cell = prev;
				} else {
					prev.next = next;
					next.prev = prev;
				}
				break;
			}
		}
		void deleteFirst() {
			if (cell.prev == null) {
				cell = null;
			} else {
				cell.prev.next = null;
				cell = cell.prev;
			}
		}
		void deleteLast() {
			if (lastCell.next == null) {
				cell = null;
				lastCell = null;
			} else {
				lastCell = lastCell.next;
				lastCell.prev = null;
			}
		}
		void debugPrint() {
			Cell c = cell;
			while (c != null) {
				System.out.print("[" + (c.prev == null ? "null" : c.prev.v) + ", " + c.v + ", " + (c.next == null ? "null" : c.next.v) + "]" + (c.prev == null ? "\n" : " "));
				c = c.prev;
			}
		}
		void print() {
			Cell c = cell;
			while (c != null) {
				System.out.print(c.v + (c.prev == null ? "\n" : " "));
				c = c.prev;
			}
		}
	}
	void run() throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		List list = new List();
		for (int i = 0; i < n; i++) {
			String command = br.readLine();
			int val = 0;
			if (command.charAt(6) == ' ') {
				val = Integer.parseInt(command.substring(7));
				command = command.substring(0, 6);
			}
			switch (command) {
			case "insert":
				list.insert(val);
				break;
			case "delete":
				list.delete(val);
				break;
			case "deleteFirst":
				list.deleteFirst();
				break;
			case "deleteLast":
				list.deleteLast();
				break;
			}
		}
		list.print();
	}
	public static void main(String[] args) {
		try {
			new Main().run();
		} catch (Exception e){
			e.printStackTrace();
		}
	}
}



Measured memory_bytes: 139140
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    long n = nextLong();
    long a = nextLong();
    long b = nextLong();

    long ans = 0;

    //ABの設置はtimes回行われている。
    long times = n/(a+b);

    long ama = n%(a+b);

    ans += times*a;

    //あとははみ出た分
    if(ama<=a){ //全部青
      ans += ama;
    }
    else{
      ans += a;
    }
    
    System.out.println(ans);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int xv = x2-x1, yv = y2-y1;
    cout
        << x2 - yv << " "
        << y2 + xv << " "
        << x1 - yv << " "
        << y1 + xv << " " << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, d, x;
    cin >> n >> d >> x;
    rep(i, 0, n){
        int a;
        cin >> a;
        x += (d - 1) / a + 1;
    }
    cout << x << endl;
}

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

typedef long long ll;
const ll MOD = 1e9+7;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    int rest=a-b;
    cout<<max(0,c-rest);



    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count=0;
        int minj;
        int i, j;
        for(i=0;i<n-1;i++){
            minj = i;
            for(j=i;j<n;j++){
                if(A[minj] > A[j]){
                    minj = j;
                }
            }
            if(i != minj){
                int tmp;
                tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp;
                count++;
            }

        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
}

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

const int m = 10;

bool exist_loop(const vector<vector<int>>& edge, int p, vector<int>& st, vector<vector<int>>& bc, const vector<int>& parbc) {
    if (st[p] == 1) {
        for (int i = 0; i < m; ++i)
            if (parbc[i] > bc[p][i] + 1) return false;

        return true;
    }
    if (st[p] == 2) return false;
    st[p] = 1;
    for (int i = 0; i < m; ++i)
        bc[p][i] = parbc[i] + ((p >> i) & 1);
    for (int e : edge[p])
        if (exist_loop(edge, e, st, bc, bc[p]))
            return true;

    st[p] = 2;
    return false;
}

bool exist_loop(const vector<vector<int>>& edge) {
    int n = edge.size();
    vector<int> st(n);
    for (int i = 0; i < n; ++i) {
        vector<vector<int>> bc(n, vector<int>(m));
        if (exist_loop(edge, i, st, bc, vector<int>(m)))
            return true;
    }
    return false;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        string s;
        cin >> s;
        vector<vector<bool>> v(1 << m, vector<bool>(m));
        vector<vector<int>> edge(1 << m);
        vector<int> par(1 << m, -1);
        int st = 0;
        for (char c : s) {
            if (c == 'u') st = 0;
            else {
                int i = c - '0';
                if (st & (1 << i)) goto A;
                v[st][i] = true;
                st |= 1 << i;
            }
        }
        for (int i = 0; i < (1 << m); ++i) {
            int msk = 0;
            for (int j = 0; j < m; ++j)
                if (v[i][j])
                    msk |= 1 << j;

            if (!msk) continue;
            for (int j = 0; j < (1 << m); ++j)
                if (!(i & j) && (j & msk))
                    edge[i].push_back(j);
        }
        if (exist_loop(edge)) goto A;

        cout << "SAFE\n";
        continue;
        A:
        cout << "UNSAFE\n";
    }
}



Measured memory_bytes: 3368
n = int(input())
s = input()
l,r = 0,0
ans = ''

for i in s:
    ans += i
    if i=='(':
        l += 1
    else:
        r += 1
    if l-r<0:
        ans = '(' + ans
        l += 1

diff = l-r
ans += ')' * diff
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, m;
    int[] as, bs, cs, ds;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        m = sc.nextInt();
        as = new int[n];
        bs = new int[n];
        cs = new int[m];
        ds = new int[m];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
            bs[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            cs[i] = sc.nextInt();
            ds[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        for (int i = 0; i < n; i++) {
            int minDistance = Integer.MAX_VALUE;
            int minCheckpoint = -1;
            for (int j = 0; j < m; j++) {
                int manhattan = Math.abs(as[i] - cs[j]) + Math.abs(bs[i] - ds[j]);
                if (manhattan < minDistance) {
                    minDistance = manhattan;
                    minCheckpoint = j;
                }
            }
            System.out.println(minCheckpoint + 1);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 19284
A, B, C, X = [int(input()) for i in range(4)]
cnt = 0

for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if 500 * a + 100 * b + 50 * c == X:
        cnt += 1
print(cnt)

Measured memory_bytes: 9116
#include<iostream>
#include<vector>
#include<string>

int main(){
    int N;
    std::cin >> N;
    std::string S, T;
    std::cin >> S >> T;
    std::string out;
    for(int i = 0; i < 2 * N; i++){
        if(i % 2 == 0) out += S[i / 2];
        else out += T[(i - 1) / 2];
    }
    std::cout << out << std::endl;
    return 0;
}


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

class Union_Find{
  vector<int> par; vector<int> rank; vector<int> num;
public:
  Union_Find(int n) {
    par = vector<int>(n); rank = vector<int>(n,0); num = vector<int>(n,1);
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if(par[x] == x) return x;
    else  return par[x] = find(par[x]);
  }
  int number(int x) {
    return num[find(x)];
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    num[x] += num[y];
  } 
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

struct edge {int u, v; ll cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;

int kruskal(int n) {
  sort(es.begin(),es.end(),comp);
  Union_Find uf(n);
  ll res = 0;
  for(auto e : es) {
    if(!uf.same(e.u,e.v)){
      uf.unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int x, y; ll w;
    cin >> x >> y >> w;
    es.push_back(edge{x,y,w});
  }
  cout << kruskal(n) << endl;
}


Measured memory_bytes: 4976
# coding: utf-8
# Your code here!
while True:
    H, W = map(int, input().rstrip().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i % 2 == 0 and j % 2 ==0 or i % 2 and j % 2:
                if j == W - 1:
                    print("#")
                else:
                    print("#", end="")
            else:
                if j == W - 1:
                    print(".")
                else:
                    print(".", end="")
    print()




Measured memory_bytes: 7040
k,x = gets.chomp.split(" ").map{|i|i = i.to_i}

((k*2)-1).times do|i|
  n = (x-(k-1)) + i
  if(n >= -1000000 && n <= 1000000) then
    if(n == ( (x-(k-1)) + ((k*2)-2) ) || n == 1000000 )
      puts(n);
    else
      printf("%d ",n);
    end
  end

end



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, k, ans=0;
	vector<int> v;

	cin>> n >> k;
	v.resize(n);

	rep(i, n) cin >> v[i];
	
	sort(v.begin(), v.end());

	rep(i, k) {
		ans+=v[i];
	}

	cout<< ans << endl;
 
	return 0;
}

Measured memory_bytes: 3628
#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define F first
#define S second 
#define pb push_back
#define endl "\n"

#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

#ifdef DEBUG
    #define dbg(s) {s;}
#endif

#ifndef DEBUG
    #define dbg(s)
#endif

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, x-1]
    return uniform_int_distribution<int>(0, x - 1)(rng);
}

#define int ll
#define i32 int32_t

#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 

#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;

int getInt () {
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}


ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 

const ll mod = 1e9 + 7;

ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int maxn = 1e6 + 7;

const ll inf = 1e9 + 7;


i32 main() {
    //freopen("<file>.in", "r", stdin);
    //freopen("<file>.out", "w", stdout);

    IOS;
    int n;
    cin>>n;

    string s;
    cin>>s;

    int ans = 1;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            continue;
        ans++;
    }

    cout<<ans<<endl;
    
}





Measured memory_bytes: 512
n,m = map(int,input().split())
lis = [0 for i in range(m)]
for i in range(n):
    s = list(map(int,input().split()))
    for j in range(s[0]):
        lis[s[j+1]-1] += 1
ans = 0
for i in range(m):
    if lis[i] == n:ans += 1
print(ans)

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

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

	long long ans = 0, sum, tmp;
	for (int bit = 0; bit < (1 << (s.size() - 1)); bit++) {
		sum = 0;
		tmp = s[0] - '0';
		for (int i = 0; i < s.size() - 1; i++) {
			if (bit & (1 << i)) {
				sum += tmp;
				tmp = 0;
			}
			tmp = tmp * 10 + s[i + 1] - '0';
		}
		sum += tmp;
		ans += sum;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define BLACK 2
#define GRAY 1

int n, M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
    
    for(int i=0; i<n; i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
    
    d[0]=0;
    
    while (1) {
        minv=INFTY;
        u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    
    int sum =0;
    for(int i=0; i<n; i++){
        if(p[i] != -1) sum+= M[i][p[i]];
    }
    return sum;
}

int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int e;
            scanf("%d",&e);
            M[i][j] = (e == -1) ? INFTY:e;
            
        }
    }
    printf("%d\n", prim());
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M, i, j; cin >> N >> M; int s[M], c[M];
for(i=0; i<M; i++){ cin >> s[i] >> c[i]; } 
for(i=0; i<1000; i++){
string st=to_string(i);
if(st.size()==N){
int k=0;
for(j=0; j<M; j++){ if(st[s[j]-1]-'0'==c[j]){ k++; } }
if(k==M){ cout << i << "\n"; return 0; }
}
} 
cout << -1 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll X, Y;
  cin >> X >> Y;
  cout << X+Y/2 << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,u) for(int i=hd[u],v;v=to[i],i;i=nxt[i])
using namespace std;
typedef long long ll;
const int N=int(1e5)+10;

int n,m,len,px,py,tot; int dep[N],sum[N],K[N],que[N]; ll res;
int hd[N],to[N*2],nxt[N*2],ecnt;
void addE(int u,int v){ to[++ecnt]=v,nxt[ecnt]=hd[u],hd[u]=ecnt; }
void dae(int u,int v){ addE(u,v),addE(v,u); }

void dfs1(int p,int fa=0,int c=1,int d=1){
	dep[p]=d,sum[p]=c;
	REP(i,p) if(v!=fa){
		if(!dep[v]) dfs1(v,p,-c,d+1);
		else px=p,py=v,len=dep[p]-dep[v]+1;
	}
}

bool prework(){
	for(int i=1;i<=n;i++) tot+=sum[i]; tot=-tot;
	if(!(len&1) && tot) return 0;
	if(len&1 && abs(tot)&1) return 0;
	return 1;
}

void dfs2(int p,int fa=0){
	if(!fa) memset(dep,0,sizeof(dep));
    dep[p]=1;
    REP(i,p) if(!dep[v])
		dfs2(v,p),sum[p]+=sum[v],K[p]+=K[v];
}

int main(){
//	freopen("father.in","r",stdin);
//	freopen("father.out","w",stdout);
	
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d",&u,&v),dae(u,v);
	dfs1(1);
	
	if(!prework()) return cout<<-1,0;
	if(len&1) tot/=2,sum[px]+=tot,sum[py]+=tot,res+=abs(tot);
	else K[px]++,K[py]--;
	
	dfs2(1); int len=1;
	for(int i=1;i<=n;i++)
		if(!K[i]) res+=abs(sum[i]);
		else que[++len]=K[i]*sum[i];
	sort(que+1,que+len+1);
	
	int mid=que[(len+1)>>1];
	for(int i=1;i<=len;i++)
		res+=abs(que[i]-mid);
	
	return cout<<res,0;
} 

Measured memory_bytes: 14936
package main
import (
	"fmt"
	"bufio"
	"os"
	"strings"
)


func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	text := stdin.Text()
	texts := strings.Split(text, "")
	a_count := 0
	b_count := 0
	haveBus := false
	for _, s := range texts {
		switch s {
		case "A":
			a_count ++
		case "B":
			b_count ++
		default:
		}
		if (a_count >= 1 && b_count >= 1) {
			haveBus = true
			break
		}
	}
	var answer string
	if haveBus {
		answer = "Yes"
	} else {
		answer = "No"
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(O: str, E: str):
    ans = ""
    for o, e in zip(O, E):
        ans += o+e
    if len(O)-len(E) == 1:
        ans += O[-1]
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    O = next(tokens)  # type: str
    E = next(tokens)  # type: str
    solve(O, E)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    char a;
    cin >> a;
    if(a - 'a'>=0&& a-'a'<='z'-'a'){
        cout << "a" << endl; 
    }else{
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
struct Vec{
	unsigned long x;
	unsigned long y;
};
bool ydesc( const Vec& left, const Vec& right ) {
    return left.y == right.y  ? left.y> right.y: left.y > right.y;
}
using namespace std;
int main(void){
	int N;
	unsigned long A,B,ans = (unsigned long)0,eq = (unsigned long)0,dif = (unsigned long)0;
	scanf("%d", &N);
	vector<Vec> v;
	for(int i=0;i< N;i++){
		scanf("%lu%lu",&A,&B);
		if(A<B){
			ans += B;
			dif +=B-A;
		}else if(A == B){
			eq += B;
		}else{
			Vec s = {A,B}; 
			v.push_back(s);
		}
	}
	sort(v.begin(),v.end(),ydesc);
	if(ans > (unsigned long)0) ans += eq;

	bool flag = true;
	while(dif > (unsigned long)0){
		flag=true;
		for(int i=0;i<v.size();i++){
			if(v[i].x - v[i].y < dif && v[i].x - v[i].y > (unsigned long)0){
				dif -= (v[i].x - v[i].y);
				ans += v[i].y;
				v[i].x = (unsigned long)0;
				v[i].y = (unsigned long)0;
				flag = false;
			}
		}
		if(flag)break;
	}
	printf("%lu\n",ans);
	fflush(stdout);

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
  string s,t;
  int count = 0;
  cin>> s >> t;
  rep(i,s.size()){
    if(s[i]!=t[i])count++;
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h> 
    //#define M_PI 3.14159265358979323846



using namespace std;
#define M 1000000007
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<ll >());
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define fi first
#define se second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define mp make_pair
#define endl "\n" 
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
 
 int main(){
     int n;cin>>n;vi arr(n);
     ll sum=0;
     rep(i,0,n){
         cin>>arr[i];
     }
     rep(i,1,sz(arr)){
         if(arr[i]>=arr[i-1])continue;
         else sum+=arr[i-1]-arr[i],arr[i]=arr[i-1];

     }
     cout<<sum<<endl;
 }

Measured memory_bytes: 3972
#include <cstdio>
#include <algorithm>
#define maxn 55
using namespace std;
int n,m,q,st=maxn,ed=0,sum;
int a[maxn],b[maxn],c[maxn],d[maxn],p[15];
void dfs(int step){
	int i,j;
	if(step==ed+1){
		int t=0;
		for(j=1;j<=q;j++)
			if(p[b[j]]-p[a[j]]==c[j])t+=d[j];
		sum=max(sum,t);
		return;
	}
	for(i=p[step-1];i<=m;i++){
		p[step]=i;
		dfs(step+1);
	}
}
int main(){
	int i;
	scanf("%d%d%d",&n,&m,&q);
	for(i=1;i<=q;i++)scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]),st=min(st,a[i]),ed=max(ed,b[i]);
	ed=ed-st+1,st=1,p[0]=1;
	dfs(1);
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1728
class Vector():
    def __init__(self):
        self.vector = []

    def pushBack(self, x):
        self.vector.append(x)

    def randomAccess(self, p):
        return self.vector[p]

    def popBack(self):
        self.vector.pop()


num_queue = int(input())
vector = Vector()

for i in range(0, num_queue):
    queue = tuple(map(int, input().split(' ')))
    if queue[0] == 0:
        vector.pushBack(queue[1])
    elif queue[0] == 1:
        print(f'{vector.randomAccess(queue[1])}')
    elif queue[0] == 2:
        vector.popBack()


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string t = "keyence";
  if (s == t) {
    cout << "YES" << endl;
    return 0;
  }
  if (s.substr(0, 7) == t) {
    cout << "YES" << endl;
    return 0;
  }
  if (s.substr(n - 7, 7) == t) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 1; i < 7; i++) {
    int j = 7 - i;
    if (s.substr(0, i) == t.substr(0, i) && s.substr(n - j, j) == t.substr(i, j)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
  
      



Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int count = 0;

        for (int a=0; a<=A; a++) {
            for(int b=0; b<=B; b++){
                for(int c=0; c<=C; c++){
                    int total = 500 * a + 100 * b + 50 * c; 
                    if (total == X) { count +=1 ;}
                }
            }
        }
        System.out.println(count);
	}
}

Measured memory_bytes: 23764
#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#ifdef bhartiya
#define endl '\n'
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define inf 200000000000000ll
// #define inf 10000000000ll
#define mod 1000000007ll
// #define mod 998244353ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }

const ll maxn = 1005;
string s[1005];
ll dp[maxn][maxn];
bool vis[maxn][maxn];

ll dfs(ll i, ll j){
    if(i<0 || j<0){
        return 0;
    }
    if(vis[i][j]) return dp[i][j];
    vis[i][j] = true;
    ll a=0,b=0;
    if(i>0 && s[i-1][j] == '.'){
        a = dfs(i-1,j);
    }
    if(j>0 && s[i][j-1] == '.'){
        b = dfs(i,j-1);
    }
    dp[i][j] = (a+b)%mod;
    return dp[i][j];
}

int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    // cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        rep(i,n){
            cin>>s[i];
        }
        dp[0][0] = 1;
        vis[0][0] = true;
        dfs(n-1,m-1);
        trace(dp[0][1]);
        trace(dp[1][0]);
        trace(dp[1][1]);
        cout<<dp[n-1][m-1];
    }
}


Measured memory_bytes: 10240