akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vi>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 998244353
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q, i, b, c, sum=0, a;
    cin>>n;
    mii m;
    for (i=0; i<n; i++)
    {
        cin>>a;
        m[a]++;
        sum+=a;
    }
    cin>>q;
    while (q--)
    {
        cin>>b>>c;
        sum+=m[b]*(c-b);
        m[c]+=m[b];
        m[b]=0;
        cout<<sum<<'\n';
    }
}


Measured memory_bytes: 9524
x,n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
h = {}
a.each{|i| h[i] = true}

dif = 100
ans = 0
(-100..101).each{|i|
  if !h[i] && dif > (x-i).abs
    ans = i
    dif = (x-i).abs
  end
}

p ans


Measured memory_bytes: 14272
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		if (a<=b){
            for (int i=0;i<b;i++){
                System.out.print(a);
            }
        }else if (a>b){
            for (int i=0;i<a;i++){
                System.out.print(b);
            }
        }
		sc.close();
		}

	}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define dump(x) cerr << #x << " = " << (x) << endl;
//定数
#define INF 1e9
#define MOD (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
//今回の変数
//使用する関数
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; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s[] ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string c;
  cin >> c;
  REP(i,7){
    if(c==s[i]){
      cout<<7-i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e2+5; int P;
int n, m, K, f[N][N], g[N][N], pw[N][N], coe[N][N][N][2], C[N][N]; void fix(int &x) { x<P?0:x-=P; }
int main()
{
    scanf("%d%d%d%d", &n, &m, &K, &P); if(n < m) swap(n, m); f[0][0] = 1;
    for(int i = 0, j; i <= n; ++i) for(C[i][0] = 1, j = 1; j <= i; fix(C[i][j]=C[i-1][j-1]+C[i-1][j]), ++j);
    for(int i = 0, j; i <= K; ++i) for(pw[i][0] = 1, j = 1; j <= n; pw[i][j] = (i64)pw[i][j-1]*i%P, ++j);
    for(int v = 1; v <= K; ++v) for(int i = 0, j; i <= m; ++i) for(coe[v][i][0][0] = 1, j = 1; j <= n; ++j) 
        coe[v][i][j][0] = (i64)coe[v][i][j-1][0]*pw[K-v+1][i]%P*(pw[v][m-i]+P-pw[v-1][m-i])%P;
    for(int v = 1; v <= K; ++v) for(int i = 0, j; i <= n; ++i) for(coe[v][i][0][1] = 1, j = 1; j <= m; ++j) 
        coe[v][i][j][1] = (i64)coe[v][i][j-1][1]*pw[v][n-i]%P*(pw[K-v+1][i]+P-pw[K-v][i])%P;
    for(int v = 1; v <= K; ++v) for(int d = 0; d < 2; ++d)
    {
        for(int i = 0; i <= n; ++i) for(int j = 0; j <= m; ++j) if(f[i][j])
            if(!d) for(int k = 0; i+k <= n; ++k) fix(g[i+k][j]+=(i64)coe[v][j][k][0]*f[i][j]%P*C[n-i][k]%P);
            else for(int k = 0; j+k <= m; ++k) fix(g[i][j+k]+=(i64)coe[v][i][k][1]*f[i][j]%P*C[m-j][k]%P);
        memcpy(f, g, sizeof(f)), memset(g, 0, sizeof(g));
    }  
    printf("%d\n", f[n][m]);
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;

  set<int> s;

  REP(i,n) {
    int a;
    cin>>a;
    s.insert(a);
  }

  if(s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

int dp[2][1000100];

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    if(s[0]=='E'){
        dp[0][0] = 1;
    }
    else{
        dp[1][0] = 1;
    }
    rep(i,n-1){
        if(s[i+1] == 'E'){
            dp[0][i+1] = 1 + dp[0][i];
            dp[1][i+1] = dp[1][i];
        }
        else{
            dp[1][i+1] = 1 + dp[1][i];
            dp[0][i+1] = dp[0][i];
        }
    }
    int ans = 100100100;
    rep(i,n){
        int cnt =0;
        if(i==0){
            cnt += dp[0][n-1] -dp[0][0];
        }
        else if(i==n-1){
            cnt += dp[1][n-2];
        }
        else{
            cnt += dp[1][i-1] + dp[0][n-1]-dp[0][i];
        }
        
        ans = min(cnt,ans);
    }
    
    cout << ans <<endl;
    
    
    return 0;
}































































Measured memory_bytes: 5892
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  long long int a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (k%2 == 0 ? a-b : b-a) << endl;

  return 0;
}




//


Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int x, y, z;

            while (true)
            {
                string[] num = Console.ReadLine().Split(' ');
                x = int.Parse(num[0]);
                y = int.Parse(num[1]);

                if (x > y)
                {
                    z = x;
                    x = y;
                    y = z;
                }
                if (x == 0 && y == 0)
                {
                    break;
                }
                
                Console.WriteLine(x + " " + y);   
            }
        }
    }



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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    vector<int> cnt(200001,0);
    rep(i,n){
        cnt[a[i]]++;
    }
    
    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(), cnt.end());
    
    int sum = n;
    
    for(int i = 0; i < k; i++){
        sum -= cnt[i];
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    StringBuilder bl = new StringBuilder();
    int id,l,r,root=-1;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Node [] node = new Node[n];

    for(int i = 0; i<n; i++){
      node[i] = new Node();
    }

    for(int i = 0; i<n; i++){
      id = sc.nextInt();
      l = sc.nextInt();
      r = sc.nextInt();
      node[id].left = l;
      node[id].right = r;
      if(l != -1) node[l].parent = id;
      if(r != -1) node[r].parent = id;
    }

    for(int i = 0;i<n; i++){
      if(node[i].parent==-1)root = i;
    }
    bl.append("Preorder\n");
    Pre_order(root, node,bl);
    bl.append("\nInorder\n");
    In_order(root, node, bl);
    bl.append("\nPostorder\n");
    Post_order(root, node,bl);
    System.out.println(bl);

  }
  static void Pre_order(int u, Node node[], StringBuilder bl){
    if(u==-1){
      return ;
    }
    bl.append(' ').append(u);
    Pre_order(node[u].left,node,bl);
    Pre_order(node[u].right,node,bl);

  }

  static void In_order(int u, Node node[], StringBuilder bl){
    if(u == -1){
      return;
    }
    In_order(node[u].left, node, bl);
    bl.append(' ').append(u);
    In_order(node[u].right, node,bl);
  }

  static void Post_order(int u, Node node[], StringBuilder bl){
    if(u == -1){
      return;
    }
    Post_order(node[u].left, node, bl);
    Post_order(node[u].right, node,bl);
    bl.append(' ').append(u);
  }

}

class Node{
  int parent = -1;
  int left = -1;
  int right = -1;
}


Measured memory_bytes: 26504
n=int(input())
c=input()
s=0
t=n-1
ans=0
while s<t and s<n and t>=0:
    while c[s]=='R':
        s+=1
        if not s<n:
            break
    while c[t]=='W':
        t-=1
        if not t>=0:
            break
    if s<t:
        ans+=1
        s+=1
        t-=1
    else:
        break
print(ans)

Measured memory_bytes: 9516
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	var count = new Array(H);
	var access = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
		count[i] = new Array(W).fill(0);
		access[i] = new Array(W).fill(false);
	}
	var queue = [[0,0]];
	access[0][0] = true;
	count[0][0] = 1;
	var mod = 1000000007;
	var dy = [1,0];
	var dx = [0,1];
	while(queue.length > 0){
		var tmp = queue.shift();
		for(var i = 0; i < 2; i++){
			var nextY = tmp[0] + dy[i];
			var nextX = tmp[1] + dx[i];
			if(nextY < H && nextY >= 0 && nextX < W && nextX >= 0){
				if(list[nextY][nextX] == "." && !access[nextY][nextX]){
					var add = count[tmp[0]][tmp[1]];
					if(i == 0 && nextX > 0){
						add += count[nextY][nextX - 1];
					}else if(i == 1 && nextY > 0){
						add += count[nextY - 1][nextX];
					}
					count[nextY][nextX] = (add % mod);
					access[nextY][nextX] = true;
					queue.push([nextY, nextX]);
				}
			}
		}
	}
	myout(count[H - 1][W - 1]);
}

Measured memory_bytes: 64268
#include<stdio.h>
int main(void){

	int A[100]={0},N,i,a,b;
	
	scanf("%d",&N);
	
	for(i=0;i<=N-1;i++){
		scanf("%d",&A[i]);
	}
	a=A[0];
	for(i=1;i<N;i++){
		if(a<A[i]){
			a=A[i];
		}else{
			continue;
	}	}
	b=A[0];
	for(i=1;i<N;i++){
		if(b>A[i]){
			b=A[i];
		}else{
			continue;
	}	}
	
	printf("%d",a-b);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<iomanip>
#include<vector>

using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;


int main(){
	ll n;
	cin>>n;
	ll a[n],b[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
		mx = max(mx,a[i]);
	}
    ll	mx1 =0;
	for(ll i=0; i<n; i++){
		if(mx == a[i]) mx1++;
	}
	ll mx2=0;
	for(ll i=0; i<n; i++){
		if(a[i]!=mx){
			mx2 = max(mx2,a[i]);
		}
	}
	for(ll i=0; i<n; i++){
		if(a[i]!=mx){
			cout<<mx<<endl;
		} else if(a[i] == mx){
			if(mx1 > 1) cout<<mx<<endl;
			else cout<<mx2<<endl;
		}
	}
}

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

int main()
{
	long long x;

	cin >> x;

    if(x % 11 == 0)
        cout << 2 * (x / 11) << endl;
	else if(x % 11 <= 6)
        cout << 2 * (x / 11) + 1 << endl;
    else
        cout << 2 * (x / 11) + 2 << endl;

	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMC = ReadIntegersWithSpaces();
            int N = NMC[0];
            int M = NMC[1];
            int C = NMC[2];

            var BList = ReadIntegersWithSpaces();

            List<List<int>> AMatrix = new List<List<int>>();

            for(int k = 1; k <= N; k++)
            {
                AMatrix.Add(ReadIntegersWithSpaces());
            }

            int count = 0;
            int sum = 0;
            foreach(var row in AMatrix)
            {
                for(int k = 0; k <= M - 1; k++)
                {
                    sum += row[k] * BList[k];
                }
                sum += C;

                if(sum > 0)
                {
                    count++;
                }
                sum = 0;
            }

            Console.WriteLine(count);
        }


        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static List<int> ReadIntList(int length)
        {
            var list = new List<int>();
            for(int k = 1; k <= length; k++)
            {
                list.Add(ReadInt());
            }

            return list;
        }

        public static List<int> ReadIntegersWithSpaces()
        {
            var strings = Console.ReadLine().Split(' ');
            var integers = new List<int>();
            foreach(var str in strings)
            {
                integers.Add(int.Parse(str));
            }

            return integers;
        }

        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        public static List<long> ReadLongList(int length)
        {
            var list = new List<long>();
            for (int k = 1; k <= length; k++)
            {
                list.Add(ReadLong());
            }

            return list;
        }
    }
}


Measured memory_bytes: 13268
#include<string>
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	string s;
	int k,cnt=0;
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1')cnt++;
		else break;
	}
	if (k <= cnt)
		cout << '1' << endl;
	else
		cout << s[cnt] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, m;
	cin >> n >> m;
	VI a(m);
	int sum = 0;
	REP(i, m) {
		cin >> a[i];
		sum += a[i];
	}
	cout << (sum > n ? -1 : n - sum) << endl;
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<math.h>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	int a[10010];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		while (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++)sort(s[i].begin(),s[i].end());
    sort(s,s+n);
    ll ans=0;
    for(int i=0;i<n;i++){
        string ch=s[i];
        int l=i,r=n-1,an=i;
        while(l<=r){
            int m=(l+r)/2;
            if(s[m]==ch){
                l=m+1;
                an=m;
            }
            else r=m-1;
        }
        ans+=r-i;
    }
    cout<<ans;

    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> G(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> G[i][j];

    int ans = -1;
    vector<vector<int>> ma(H, vector<int>(W, 1));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i == 0 or j == 0) {
                ma[i][j] = (G[i][j] == 0 ? 1 : 0);
                continue;
            }

            if (G[i][j] == 1) {
                ma[i][j] = 0;
                continue;
            }
            ma[i][j] =
                min(ma[i - 1][j - 1], min(ma[i - 1][j], ma[i][j - 1])) + 1;
        }
    }

    rep(i, H) rep(j, W) { ans = max(ma[i][j] * ma[i][j], ans); }

    // ddump(G);
    // ddump(ma);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18204
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = (1 << 31) - 1;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl A;

void input() {
	cin >> n;
}


void solve() {
	a = n;
	for (ll i = 1; i < sqrt(n) + 1; i++) {
		if (n % i == 0) {
			a = min(n / i + i - 2, a);
		}
	}

	cout << a << endl;
}

int main() {
	input();
	solve();
} 

Measured memory_bytes: 256
import numpy as np
H, W, D = list(map(int, input().split()))

px, py = [None for i in range(H*W+1)], [None for i in range(H*W+1)]
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        px[A[j]] = i
        py[A[j]] = j

d = [0 for i in range(H*W+1)]
for i in range(D+1, H*W+1):
    d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())

for i in range(Q):
    L, R = list(map(int, input().split()))
    print(d[R]-d[L])

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> cost(m);
    vector<vector<bool>> opens(m, vector<bool>(n));
    rep(i,m){
        int a,b;
        cin >> cost.at(i) >> b;
        rep(j,b){
            int c;
            cin >> c;
            opens.at(i).at(c-1) = true;
        }
    }
    map<vector<bool>,int> mp;
    for(int bits=0;bits<(1<<n);bits++){
        vector<bool> v(n);
        for(int i=0;i<n;i++){
            if(bits & (1<<i)){
                v.at(i) = true;
            }
            else {
                v.at(i) = false;
            }
        }
        mp[v] = bits;
    }

    vector<int> keycd(m);
    rep(i,m){
        keycd.at(i) = mp[opens.at(i)];
    }

    vector<int> dp(1<<n);
    rep(i,dp.size()){
        dp.at(i) = INF;
    }
    dp.at(0) = 0;

    rep(i,m){
        for(int bits=0;bits<(1<<n);bits++){
            if(dp.at(bits) == INF) continue;
            int nc = bits | keycd.at(i);
            int nm = dp.at(bits) + cost.at(i);
            dp.at(nc) = min(dp.at(nc),nm);
        }
    }
    int allopened = (1<<n)-1;
    if(dp.at(allopened) == INF) dp.at(allopened) = -1;
    cout << dp.at(allopened) << endl;
    return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    if(a+b >=10) cout << "error"<< endl;
    else cout << a+b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int h,w;
    cin >> h >> w;
    string s;
    int temp=0;
    rep(i,h){
        cin >> s;
        rep(j,w){
            if(s[j]=='#') temp++;
        }
    }
    if(temp==h+w-1){
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n; cin >> n;
  int a;
  bool approved = true;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    if (a % 2 == 0)
    {
      if (a % 3 != 0 && a % 5 != 0)
      {
        approved = false;
        break;
      }
    }
  }
  if (approved) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 3580
let cnt = ref 0

let merge a l m r =
  let ni = m - l in
  let nj = r - m in
  let init_ary n p =
    Array.init (n + 1) (fun i -> if i = n then max_int else a.(p + i))
  in
  let ai = init_ary ni l in
  let aj = init_ary nj m in
  let rec doit i j k =
    if k >= r then ()
    else begin
      incr cnt;
      if ai.(i) <= aj.(j) then (a.(k) <- ai.(i); doit (i + 1) j (k + 1))
      else (a.(k) <- aj.(j); doit i (j + 1) (k + 1))
    end
  in
  doit 0 0 l

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  Array.iteri (fun i e -> Printf.printf (if i = 0 then "%d" else " %d") e) a;
  print_newline ();
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 19636
/**
 *    author:  [itmo] enot.1.10
 *    created: 24.09.2016 15:04:54       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;

char s[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    scanf("%s", s);
    int k;
    scanf("%d", &k);
    int n = strlen(s);
    forn(i, n)
    {
        int c = s[i] - 'a';
        int want = (26 - c) % 26;
        if (want <= k)
        {
            k -= want;
            s[i] = 'a';
        }
        else continue;
    }
    int c = s[n - 1] - 'a';
    s[n - 1] = (c + k) % 26 + 'a';
    printf("%s\n", s);
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,d,m[100],id[100],p[100],num;
vector<int> c[100];

int main(){
  while(cin >> n >> d, n){
    num = 0;
    rep(i,n){
      cin >> m[i];

      c[i].resize(m[i]); p[i] = 0;
      rep(j,m[i]){
	cin >> c[i][j];
	p[i] += c[i][j];
      }

      num += m[i];
      id[i] = m[i]-1;
    }

    bool f = true;
    rep(i,num){
      int maxv = -1, secv = -1;
      rep(j,n){
	secv = max(secv,p[j]);
	if(secv > maxv)swap(secv,maxv);
      }

      f = false;
      rep(j,n){
	if(id[j]>=0){
	  if(p[j] == maxv){
	    if(secv<0 || secv-d<=p[j]-c[j][id[j]]){
	      p[j] -= c[j][id[j]];
	      id[j]--;
	      f = true;
	      break;
	    }
	  }else if(maxv-d<=p[j]-c[j][id[j]]){
	    p[j] -= c[j][id[j]];
	    id[j]--;
	    f = true;
	    break;
	  }
	}
      }

      if(!f)break;
    }
    cout << (f?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;

const int N=2e5+5;
int n,a[N],cnt[N][2],dem[45][45];

void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        int cur=0;
        bool have=false;
        for(int j=s.size()-1;j>=0;j--)
        {
            if(s[j]=='.')
            {
                have=true;
                break;
            }
            cur++;
        }
        if(!have) cur=0;
        for(int j=0;j<s.size();j++) if(s[j]!='.') a[i]=a[i]*10+s[j]-'0';
        cur=9-cur;
        while(cur--) a[i]*=10;
        while(a[i]%2==0)
        {
            cnt[i][0]++;
            a[i]/=2;
        }
        while(a[i]%5==0)
        {
            cnt[i][1]++;
            a[i]/=5;
        }
    }
    int res=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=max(18-cnt[i][0],0ll);j<45;j++)
        {
            for(int k=max(18-cnt[i][1],0ll);k<45;k++) res+=dem[j][k];
        }
        dem[cnt[i][0]][cnt[i][1]]++;
    }
    cout<<res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*int t;
    cin>>t;
    while(t--)*/
        solve();
}


Measured memory_bytes: 8316
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
    int n, x;
    int m[100];
    int s = 1000;
    int ans = 0;
    cin >> n >> x;
    rep(i, n) {
        cin >> m[i];
        x -= m[i];
        s = min(m[i], s);
        ans++;
    }
    cout << ans + x / s << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
towns = []
total = 0
for i in range(n):
    town = list(map(int,input().split()))
    towns.append(town)
                
for i in range(n):
    for j in range(n):
        total += ((towns[i][0] - towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)**(1/2) / n

print(total)
        

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	map<ll,int, greater<ll> > c, d;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		c[A[i]]++;
	}

	for (auto itr = c.begin(); itr != c.end(); itr++) {
		//cout << itr->first <<" "<< itr->second << endl;
		int tf, ts;
		tf = itr->first; ts = itr->second;

		if (ts >= 2) {
			d[tf] = ts;
		}
	}
	bool flag=false;
	for (auto itr = d.begin(); itr != d.end(); itr++) {
		ll Ma=0;
		if (itr->second >= 4) {
			Ma = itr->first*itr->first;
			flag=true;
		}
		else {
			Ma = itr->first;
			itr++;
			Ma *= itr->first;
			flag=true;
		}
		cout << Ma << endl;
		break;
	}
	if(!flag) cout << 0 << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int l[50];
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	int sum=0;
	sort(l,l+n);
	for(int j=n-k;j<n;j++){
		sum+=l[j];
	}
	cout<<sum<<endl;
}
	


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
  long long int N,K;
  long long int dif;
  
  if(scanf("%lld %lld",&N,&K) != 2){
    printf("***SCANF ERROR***\n");
    exit(1);
  }
  dif=N;
  do{
    N=N%K;
  }while(N/K!=0);
  
  do{
    dif=llabs(N-K);
    if(dif<N) N=dif;
  }while(dif<=N);
  printf("%lld\n",N);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

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

  if(a+b<c){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import math
def soi(x):
    y = x
    a = []
    for i in range(2,int(math.sqrt(x))+1):
        while x%i == 0:
            a.append(i)
            x/=i
    if len(a)==0 or x!=1:
        a.append(int(x))
    a.sort()
    print(str(y)+':',*a)

n = int(input())
soi(n)


Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
 
const int M = 1000000007;
 
class unionfind {
    public:
    int n;
    vector<int> par;
    unionfind(int m) {
        n = m;
        par.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i;
    }
    int find(int x) { return par[x] == x ? x : (par[x] = find(par[x])); }
    int isunion(int x, int y) { return find(x) == find(y); }
    int tounion(int x, int y) {
        int p = find(x), q = find(y);
        if (p == q) return 0;
        par[q] = p;
        return 1;
    }
};
 
int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;
 
        vector<int> h(n);
        map<int, int> mp;
        for (int i = 0; i < n; ++i) {
            cin >> h[i];
            mp[h[i]] = 1;
        }
        int cc = 0;
        for (auto& i : mp)
            i.second = cc++;
 
        vector<vector<int>> lis(n);
        for (int i = 0; i < n; ++i) {
            h[i] = mp[h[i]];
            lis[h[i]].push_back(i);
        }
        vector<vector<pair<int, pair<int, int>>>> edge(n);
        for (int i = 0; i < m; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            --a;
            --b;
            edge[min(h[a], h[b])].push_back(make_pair(c, make_pair(a, b)));
        }
        for (int i = 0; i < n; ++i)
            sort(edge[i].begin(), edge[i].end());
 
        int lastsep = n;
        unionfind puf(n);
        for (int i = n - 1; i >= 0; --i) {
            for (auto j : edge[i])
                puf.tounion(j.second.first, j.second.second);
 
            for (int j = 0; j < n; ++j) {
                if (h[j] >= i) {
                    for (int k = 0; k < n; ++k) {
                        if (h[k] >= i && !puf.isunion(j, k)) {
                            lastsep = i;
                            break;
                        }
                    }
                    break;
                }
            }
        }
        if (lastsep == 0) {
            cout << "0\n";
            continue;
        }
        vector<pair<int, pair<int, int>>> fedge;
        for (int i = lastsep - 1; i < n; ++i)
            for (auto j : edge[i])
                fedge.push_back(j);
 
        sort(fedge.begin(), fedge.end());
        unionfind uf(n);
        long long sum = 0;
        for (auto i : fedge)
            if (uf.tounion(i.second.first, i.second.second))
                sum += i.first;
 
        for (int i = lastsep - 2; i >= 0; --i)
            for (auto j : edge[i])
                if (uf.tounion(j.second.first, j.second.second))
                    sum += j.first;
 
        cout << sum << "\n";
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define MAX4 10010

using namespace std;


ll h,n;
ll dp[MAX4];
vector<pair<ll,ll> >massiv;

int main(){
FLASH;
cin>>h>>n;
for(ll i=1;i<=n;i++)
{
 ll x,y;
 cin>>x>>y;
 massiv.pb(mp(x,y));	
}

for(ll i=1;i<=h;i++)dp[i]=INT_MAX;


for(ll xp=0;xp<=h;xp++)
{
 for(ll i=0;i<n;i++)
 {
   ll xp_new=min(xp+massiv[i].first,h);
   dp[xp_new]=min(dp[xp_new],dp[xp]+massiv[i].second);	 
 }	
}
cout<<dp[h]<<endl;







return 0;
} 


Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string a;
    int b,c;
    
    for (int i=0;i<9;i++){
        cin >> a>>b>>c;

        cout <<a<<" "<<b+c<<" "<<200*b+300*c<<endl;
    }
      
}



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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int64_t N, X = 1000, Y = 0;
    cin >> N;
    vector<int64_t> tmp(N + 2), list;
    tmp[0] = 400, tmp[N + 1] = 0;
    for (int i = 1; i < N + 1; i++)
        cin >> tmp[i];
    for (int i = 1; i < N + 1; i++)
    {
        if (tmp[i - 1] < tmp[i] && tmp[i] >= tmp[i + 1])
            list.push_back(tmp[i]);
        if (tmp[i - 1] >= tmp[i] && tmp[i] < tmp[i + 1])
            list.push_back(tmp[i]);
    }
    for (int i = 0; i < list.size(); i += 2)
    {
        Y = X / list[i];
        X -= list[i] * Y;
        X += Y * list[i + 1];
    }
    cout << X;
}

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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long K = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();

		long a=0;//hit my pocket
		long b=0;//bisquit to yen
		long c=0;//yen to biscuit
		if (A+1>=B) {
			System.out.println(K+1);
		}else {
			a+=A-1;
			K-=A-1;
			if (K%2==0) {
				b=K/2;
				c=K/2;
			}else if(K%2==1) {
				b=(K-1)/2;
				c=(K-1)/2;
				a++;
			}
			long bisquit = 1+a+(B-A)*b;
			System.out.println(bisquit);
		}
	}
}

Measured memory_bytes: 23764
N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
import bisect
for i in range(N):
    for j in range(i+1,N-1):
        m=bisect.bisect_left(l,l[i]+l[j])
        count+=m-(j+1)
print(count)

Measured memory_bytes: 3188
#include<stdio.h>
int n,ans;char a[200001];
main()
{
	scanf("%d%s",&n,a);
	for(register int l=0,r=n-1;l<r;)
	{
		for(;l<n&&a[l]=='R';++l);
		for(;r&&a[r]=='W';--r);
		if(l<r){++ans;++l;--r;}
	}
	printf("%d",ans);
}

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

using namespace std;

int f(unsigned long long a, unsigned long long k){
	return a-1;
}

int main() {
	unsigned long long a, b, k; cin >> a >> b >> k;
	if(k >= a+b){
		cout << 0 << " " << 0;
		return 0;
	}
	if(k >= a){
		k = k - a;
		a = 0;
		b = b - k;
		cout << a << " " << b;
	} else {
		cout << a - k << " " << b;
	}
    return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
arg1 = m*6
arg2 = h*30+0.5*m
arg3 = abs(arg1-arg2)
if arg3 >= 180:
    arg3 = 360 -arg3

rad = math.radians(arg3)

ans = math.sqrt(a*a+b*b-2*a*b*math.cos(rad))
print(ans)

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

int main() {
	int N = 0;
	cin >> N;
	unsigned long long *L = new unsigned long long[N+1];
	L[0] = 2;
	L[1] = 1;
	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << L[N];
	delete[] L;
}

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

int main(){
  int N,K,Q;cin>>N>>K>>Q;
  int C[120000]={};
  for(int i=0;i<Q;i++){
    int A;
      cin>>A;
      C[A-1]++;
  }
  for(int i=0;i<N;i++){
    if(K-(Q-C[i])<=0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000003
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, m, sum = 0, res = 0;
    cin>>n;
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++)
    {
        if(i < n)
            cout<<s[i];
        else{
            cout<<"...";
            break;}
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main () {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);
  for (int i=0; i<m; i++){
    int a,b;
    cin >>a>>b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for (int i=0; i<n;i++){
    cout << vec.at(i) <<endl;
  }
}

Measured memory_bytes: 256
S=input()
CHAR=['dream','dreamer','erase','eraser']
reverse_S=S[::-1]
reverse_CHAR=[]
for i in range(len(CHAR)):
  reverse_CHAR.append(CHAR[i][::-1])

i=0
keizoku=True
while i < len(reverse_S) and keizoku==True:
  for j in range(len(reverse_CHAR)):
    if reverse_S[i:i+len(reverse_CHAR[j])]==reverse_CHAR[j]:
      i+=len(reverse_CHAR[j])
      break
    else:
      if j==(len(reverse_CHAR)-1):
        keizoku=False

if keizoku==True:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3188
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

ans = [0] * (h * w)
index = 0
for i in range(n):
    for j in range(index, index + a[i]):
        ans[j] = i + 1
        index += 1

for i in range(h):
    row = ans[i * w: (i + 1) * w]
    if i % 2 == 1:
        row = row[::-1]
    for x in row:
        print(x, end = " ")
    print()

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

const char sp = ' ';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int k, s;
    cin >> k >> s;

    int cnt = 0;
    for(int x = 0; x <= k; ++x){
        for(int y = 0; y <= k; ++y){
            if(0 <= s-x-y and s-x-y <= k) ++cnt;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    string s; cin >> s;
    int si = SIZE(s);
    int b=-1,e;
    rep(i,si){
        if(s[i] == 'A' && b == -1) b = i;
        if(s[i] == 'Z' ) e = i;
    }
    cout << e-b+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision

using namespace std;
using p = pair<int,int>;
bool vectorcheck(vector<int>& x,vector<int>& y,int size){
            for (int i = 0; i < size; i++)
            {
                if(x[i] != y[i]) return false;
            }
            return true;
}
int main(){
    int n; cin >> n;
    vector<int> a(n),b(n);
    vector<int> perm(n);
    for (int i = 0; i < n; i++) cin >>  a[i];
    for (int i = 0; i < n; i++) cin >>  b[i];
    for (int i = 1; i <= n; i++) perm[i-1] = i;    

    int dictnum=0,t=0,s=0;
    do{ 
        dictnum++;
        if(vectorcheck(perm,a,n)) t = dictnum;
        if(vectorcheck(perm,b,n)) s = dictnum;
    }while(next_permutation(perm.begin(),perm.end()));
    
    cout << abs(t-s) << endl;
    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#include <unistd.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
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}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 = (ll)1e18 + 1;
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() {
  int n, x;
  cin >> n >> x;
  vi s(n);
  rep (i, n) {
    cin >> s[i];
  }
  sort(all(s));
  reverse(all(s));

  vll dp(n + 1, vl(x + 1));
  dp[0][x] = 1;

  rep (i, n) {
    rep (j, x + 1) {
      if (dp[i][j] == 0) continue;
      (dp[i + 1][j] += dp[i][j] * (n - 1 - i) % MOD) %= MOD;
      (dp[i + 1][j % s[i]] += dp[i][j]) %= MOD;
    }
  }
  ll ans = 0;
  rep (i, x + 1) {
    (ans += dp[n][i] * i % MOD) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 158592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    string S;
    cin >> N;
    vector<ll> A(N);//,G(N);
    map<ll,ll> mp;
    ll ans = 0;
    rep(i,N){
        cin >> A[i];
        mp[A[i] + i]++;
        ans += mp[i-A[i]];
    }
    cout << ans << endl;
}
        /*
        if(A[i]>N-1){
        //PR(G,N);

            continue;
        }else{
            if(i-A[i]>=0 && i-A[i] <= N-1){
                
                    G[i-A[i]]++;
                
            }
            if(i+A[i]>=0 && i+A[i] <= N-1){
                //if(G[i+A[i]]>0){
                G[i+A[i]]++;
                //}
            }
        //PR(G,N);

        }*//*
    }
    ll sum = 0;
    //PR(G,N);
    rep(i,N){
        if(G[i] != 0){
            sum += (G[i]-1);
        }
    }
    cout << sum <<endl;
}*/

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

int main() {
  int N, D, X;
  cin >> N >> D;
  vector<vector<int>> data(N, vector<int>(D));
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> data.at(i).at(j);      
    }    
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int dd = 0;
      double d = 0;
      int dint = 0;
      for (int k = 0; k < D; k++) {
        dd += (data.at(i).at(k) - data.at(j).at(k)) * (data.at(i).at(k) - data.at(j).at(k));
      }
      d = sqrt(dd);
      dint = sqrt(dd);
      if (d == dint)
        count++;
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256