akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> dice(n);
    for (auto &&i : dice)
        cin >> i;
    int max_num = 0;
    for (int i = 0; i <= n - k; ++i) {
        int temp = 0;
        for (int j = i; j < i + k; ++j)
            temp += dice[j];
        max_num = max(max_num, temp);
    }
    cout << fixed << setprecision(9) << (max_num + k) / (double)2 << endl;
    return 0;
}


Measured memory_bytes: 1024
//Created by: Aditya Singh
//Bleed Blue
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define unm unordered_map<int,int>
#define pb emplace_back
#define nt _int128
#define PI 3.1415926535897932384626433
#define inf 1e18

const int N = 100005;

int dp[N], ar[N];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
        cin >> n;
        for (i = 0; i < n; i++)
        {
            cin >> ar[i];
            dp[i] = inf;
        }
        dp[0] = 0;
        for (i = 0; i < n; i++)
        {
            for (j = i + 1; j <= min(i + 2, n - 1); j++)
                dp[j] = min(dp[j], dp[i] + abs(ar[i] - ar[j]));
        }
        cout << dp[n - 1];
    }
    return 0;
}

Measured memory_bytes: 5192
n = int(input())
s = [input() for i in range(n)]

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

max_dic = max(dic.values())
ans = [i for i, j in dic.items() if j == max_dic]
ans.sort()

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 35220
#include <cassert>
#include <vector>
#include <map>
#include <algorithm>

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

ll n, a, b;

// const int K = 8;
// int main(void) {
//   int perm[K];
//   REP(i, K) {
//     perm[i] = i+1;
//   }
//   int foo[K+1];
//   int foo2[K+1];
//   do {
//     REP(i, K) {
//       printf("%d,", perm[i]);
//     }
//     int a = 0;
//     int b = 0;
//     REP(i, K) {
//       int idx = lower_bound(foo, foo+a, perm[i]) - foo;
//       foo[idx] = perm[i];
//       if(idx == a) {
//         ++a;
//       }
//       int idx2 = lower_bound(foo2, foo2+b, -perm[i]) - foo2;
//       foo2[idx2] = -perm[i];
//       if(idx2 == b) {
//         ++b;
//       }
//     }
//     printf(": A=%d, B=%d, A+B=%d\n", a, b, a+b);
//   } while(next_permutation(perm, perm+K));
//   return 0;
// }

template<typename T> struct Compression {
  vector<T> idx2orig;
  Compression(const vector<T>& values): idx2orig(values) {
    sort(idx2orig.begin(), idx2orig.end());
    idx2orig.erase(unique(idx2orig.begin(), idx2orig.end()), idx2orig.end());
  }
  int toIndex(const T& orig) const { return lower_bound(orig); }
  int fromIndex(int idx) const { assert(0 <= idx && idx < (int)idx2orig.size()); return idx2orig[idx]; }
  int size(void) const { return idx2orig.size(); }
  int lower_bound(const T& orig) const { return std::lower_bound(idx2orig.begin(), idx2orig.end(), orig) - idx2orig.begin(); }
  int upper_bound(const T& orig) const { return std::upper_bound(idx2orig.begin(), idx2orig.end(), orig) - idx2orig.begin(); }
};

int foo[2][300000+10];

int main(void) {
  cin >> n >> a >> b;
  vector<ll> res;
  const ll OFFSET = 1000000;
  int rest = n-a;
  REP(i, a) {
    res.push_back(i*OFFSET);
    REP(j, b-1) {
      if(rest <= 0) {
        break;
      }
      res.push_back(i*OFFSET - (j+1));
      --rest;
    }
  }
    // REP(i, res.size()) {
    //   printf("%lld%c", res[i], i == (int)res.size()-1 ? '\n' : ' ');
    // }

  Compression<ll> compression(res);
  REP(i, res.size()) {
    res[i] = compression.toIndex(res[i])+1;
  }

  int as[2] = {};
  REP(t, 2) {
    REP(i, res.size()) {
      int idx = lower_bound(foo[t], foo[t]+as[t], (t*2-1)*res[i]) - foo[t];
      foo[t][idx] = (t*2-1)*res[i];
      if(idx == as[t]) {
        ++as[t];
      }
    }
  }

  if(as[0] == b && as[1] == a && (int)res.size() == n) {
    REP(i, res.size()) {
      printf("%lld%c", res[i], i == (int)res.size()-1 ? '\n' : ' ');
    }
  } else {
    puts("-1");
  }
  return 0;
}


Measured memory_bytes: 9836
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 2e3;
const ll P = 1e9+7;
int N, M, S[Nmax], T[Nmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> S[i];
	for(int i=0; i<M; i++) cin >> T[i];

	vector<vector<ll> > dp(N+1, vector<ll>(M+1));
	for(int i=0; i<=N; i++) dp[i][0] = 1;
	for(int i=0; i<=M; i++) dp[0][i] = 1;

	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
			if(S[i]!=T[j]){
				dp[i+1][j+1] += P-dp[i][j];
			}
			dp[i+1][j+1] %= P;
		}
	}

	cout << dp[N][M] << endl;

	return 0;
}


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

int num[26][26][100000];
int offset[100000];

template<typename T>
struct Trie{
    static const int C = 26;
    struct Node{
        Node* ch[C];
        vector<T> val;
        int exact;
        Node(){
            exact = 0;
            fill(ch, ch+C, nullptr);
        }
    };

    Node* root;
    char start;

    Trie(char start='a'):start(start){ root = new Node(); }
    
    int getsize(Node* node){ return node ? node->val.size() : 0; }
    
    void add(Node* node, int d, const string& S, T v){
        node->val.push_back(v);
        if(S.size() == d){
            node->exact++;
        }else{
            int c = S[d] - start;
            if(!node->ch[c]) node->ch[c] = new Node();
            add(node->ch[c], d+1, S, v);
        }
    }
    void add(const string& S, T v){ add(root, 0, S, v); }

    void calc(Node* node){
        for(int i=0; i<C; i++) if(node->ch[i]) for(auto idx : node->ch[i]->val){
            offset[idx] += node->exact;
            for(int j=0; j<C; j++) if(i != j) num[i][j][idx] += getsize(node->ch[j]);
        }
        for(int c=0; c<C; c++) if(node->ch[c]) calc(node->ch[c]);
    }
    void calc(){ calc(root); }
};


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

    Trie<int> trie;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        trie.add(s, i);
    }

    trie.calc();

    int Q;
    cin >> Q;
    while(Q--){
        int k;
        string s;
        cin >> k >> s;
        k--;
        int ord = offset[k] + 1;
        vector<int> order(26);
        for(int i=0; i<26; i++) order[s[i] - 'a'] = i;
        for(int i=0; i<26; i++) for(int j=0; j<26; j++) if(order[i] > order[j]) ord += num[i][j][k];
        cout << ord << endl;
    }

    return 0;
}


Measured memory_bytes: 382716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<setprecision(3); cout<<fixed;
  #ifdef DEBUG
  freopen("ip.txt","r",stdin);
  clock_t tStart = clock();
  #endif

  int a,b; cin>>a>>b; cout<<2*b-a;



  #ifdef DEBUG
	cout<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)<<"s.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  double a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  if (2*c==a && 2*d==b) ans = 1;
  printf("%.10f %d\n", (a*b)*0.5, ans);
  return 0;
}

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

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

    int r = 1;
    while (r * 2 <= n) r *= 2;

    cout << r << endl;

    return 0;
}

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

using namespace std;

long long MAX = 1000000000000000000;

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  long long result = 1;
  for (long long i = 0; i < N; i++) {
    if (A[i] > (MAX / result)) {
      result = -1;
      break;
    }
    result *= A[i];
    if (result == 0) break;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string res = "";
    // 行き1
    for (int i = sy; i < ty; i++) {
        res += "U";
    }
    for (int i = sx; i < tx; i++) {
        res += "R";
    }

    // 帰り1
    for (int i = sy; i < ty; i++) {
        res += "D";
    }
    for (int i = sx; i < tx; i++) {
        res += "L";
    }

    // 行き2
    res += "L";
    for (int i = sy; i < ty+1; i++) {
        res += "U";
    }
    for (int i = sx; i < tx+1; i++) {
        res += "R";
    }
    res += "D";

    // 帰り2
    res += "R";
    for (int i = sy; i < ty+1; i++) {
        res += "D";
    }
    for (int i = sx; i < tx+1; i++) {
        res += "L";
    }
    res += "U";

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e6 + 500;
const int mod = 1e9 + 7;
int n,t;
int dp[N];
struct fun
{
    int t,v;
}z[N];
bool cmp(fun a, fun b)
{
    return a.t < b.t;
}
int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    ios::sync_with_stdio(false);
//    cin.tie(NULL);
    scanf("%d%d", &n, &t);
    for (int i = 0; i < n; ++i)
        scanf("%d%d", &z[i].t, &z[i].v);
    memset(dp, -1, sizeof dp);
    dp[0] = 0;
    sort(z, z + n, cmp);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
        for (int j = t - 1; j >= 0; --j)
            if (dp[j] != -1)
            {
                dp[j + z[i].t] = max(dp[j + z[i].t], dp[j] + z[i].v);
                maxx = max(maxx, dp[j + z[i].t]);
            }
    printf("%d\n", maxx);
    return 0;
}


Measured memory_bytes: 16384
#include <iostream>
using namespace std;
const int maxx=110;
const int infinity=(1<<30);

int A[maxx][maxx];
bool flag[maxx];	//用flag来标记这个节点是不是在MST中，true是在T里，false是在V-T里；

int main (){
		int n;
		cin>>n;
		for(int i =1;i<=n;i++){
			for(int j=1;j<=n;j++){
				int e;cin>>e;
				A[i][j]=(e==-1)?infinity:e;
			}
		}

		for(int i=0;i<maxx;i++) flag[i]=false;
		int sum=0,minv,minj;
		flag[1]=true;
		while(1){
			minv=infinity;
			minj=-1;
			for(int i=1;i<=n;i++){
				if(flag[i]==true){
					for(int j=1;j<=n;j++){
						if(A[i][j]!=-1 && A[i][j]<minv && flag[j]==false) {
							minv=A[i][j];
							minj=j;
						} 
					}
				}
			}
//			cout<<minj<<endl;
			if(minv==infinity || minj==-1) break;
			flag[minj]=true;
			sum+=minv;
		}
		
		cout<<sum<<endl;
		return 0;
		
}


Measured memory_bytes: 3108
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    
def Koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    Koch(n-1,x1,y1,sx,sy)
    Koch(n-1,sx,sy,ux,uy)
    Koch(n-1,ux,uy,tx,ty)
    Koch(n-1,tx,ty,x2,y2)
n=int(input())
Koch(n,0,0,100,0)
plot(100,0)


Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	ll n,k;
	cin >> n >> k;
	int count=1;
	while(1) {
		if (n < k) break;
		n /= k;
		count++;
	}
	cout << count << endl;
	
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=0x3f3f3f3f;
typedef long long ll;
int n,k;
int a[100005];
bool b[100005];
int main()
{
    memset(b,0, sizeof b);
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    bool flag=1;
    for(int i=0;i<n;i++){
        if(a[i]<a[i-1]){
            a[i]++;
        }
        if(a[i]<a[i-1])
            {flag=0;break;}
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int P=1e9+7,maxn=1e6+10;
int n,dp[maxn];
int main(){
    scanf("%d",&n);dp[n]=n;dp[n-1]=1ll*n*n%P;int s=0;
    per(i,n-2,1) dp[i]=(dp[i+1]+1ll*(n-1)*(n-1)+s+i+1)%P,s=(s+dp[i+2])%P;
    printf("%d\n",dp[1]);
    return 0;
}

Measured memory_bytes: 4096
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  if (N < 10) {
    cout << N << endl;
    return 0;
  }

  const auto n = boost::lexical_cast<string>(N);
  const auto h = boost::lexical_cast<ll>(n.front());
  const auto d = n.size();

  for (int i = 1; i < d; i++) {
    if (n[i] != '9') {
      cout << (h - 1) + 9 * (d - 1);
      return 0;
    }
  }
  cout << h + 9 * (d - 1) << endl;
  return 0;
}


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

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var rgb = sc.ArrayInt(3);
        if (int.Parse(String.Join("", rgb)) % 4 == 0) {
            WriteLine("YES");
        } else {
            WriteLine("NO");
        }
    }
    
}

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 nextInt() {
        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] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        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] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        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] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());		

void decompose(int n,map<pii,ll>&fre)
{
	vector<int>vec;
	while(n)
	{
		vec.push_back(n%10);
		n/=10;
	}
	
	fre[{vec.back(),vec[0]}]++;
}

void solve()
{
	int n;
	cin>>n;
	
	map<pii,ll>fre;
	
	for(int i=1;i<=n;i++) decompose(i,fre);
	
	ll ans=0;
	
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			ans+=fre[{i,j}]*fre[{j,i}];
		}
	}
	
	cout<<ans;
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int N=60;
int a[N];
int32_t main()
{
	int n=in();
	vector<pair<int,int>> mv;
	for(int i=1;i<=n;i++)a[i]=in();
	
	int mx=*max_element(a+1,a+n+1);
	int mn=*min_element(a+1,a+n+1);
	
	if(abs(mx)>abs(mn))
	{
		int id=max_element(a+1,a+n+1)-a;
		for(int i=1;i<=n;i++)
		{
			if(i!=id)
			{
				mv.push_back({id,i});
				a[i]+=a[id];
			}
		}
		for(int i=1;i<n;i++)
		{
			a[i+1]+=a[i];
			mv.push_back({i,i+1});
		}
	}
	else
	{
		int id=min_element(a+1,a+n+1)-a;
		for(int i=1;i<=n;i++)
		{
			if(i!=id)
			{
				mv.push_back({id,i});
				a[i]+=a[id];
			}
		}
		for(int i=n-1;i>=1;i--)
		{
			a[i]+=a[i+1];
			mv.push_back({i+1,i});
		}
	}
	cout<<mv.size()<<"\n";
	for(auto i:mv)
	{
		cout<<i.first<<" "<<i.second<<"\n";
	}
	
	//for(int i=1;i<=n;i++)cout<<a[i]<<" ";
	
	
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n+1);
    repi(i,1,n+1) cin>>a[i];
    int cnt=0,now=1;
    repi(i,1,n+1){
        cnt++;
        if(a[now]==2){
            cout<<cnt;
            return 0;
        }
        else now=a[now];
    }
    cout<<-1;
}

Measured memory_bytes: 3760
def main():
    N, M = map(int, input().split())
    students = [input().split() for _ in range(N)]
    checkpoints = [input().split() for _ in range(M) ]
    nearest = [None]*N

    for i, s in enumerate(students) :
        min_d = 10**9
        index = 0

        for j, p in enumerate(checkpoints, 1) :
            a, b = map(int, s)
            c, d = map(int, p)
            d = abs(a - c) + abs(b - d)

            if min_d > d:
                min_d = d
                index = j

        nearest[i] = index

    for i in range(N):
        print(nearest[i])   
main()


Measured memory_bytes: 3064
n,m=map(int,input().split())
A=[list(map(int,input().split()))for i in range(n)]
A=sorted(A,key=lambda x:x[0])
cnt=0
ans=0
for i in range(n):
    cnt+=A[i][1]
    if m<=cnt:
        over=cnt-m
        ans+=(A[i][0]*A[i][1])-(over*A[i][0])
        break
    else:
        ans+=A[i][0]*A[i][1]
print(ans)


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

using namespace std;

#define ll long long
#define pb push_back
#define sn "\n"

int main(){
    int n;
    cin >> n;
    int arr[n]; int counter = 0;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++){
        if (arr[i] % 2 != 0 && (i+1) % 2 != 0){
            counter++;
        }
    }
    cout << counter;
}


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

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

  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) {
      ans++;
    }
  }

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


Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> p;

ll modpow(ll x, ll m, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%m;
        x=x*x%m;
        n>>=1;
    }
    return res;
}

int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;
    
    if(a+b>=c) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    
    
    
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mod = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int t;
    cin>>t;
    
    for(int i=0;i<t;++i){
        int n;
        cin>>n;
        vector<ll> A(n);
        for(auto &a : A)cin>>a;
        string s;
        cin>>s;
        vector<ll> b;
        for(int i=n-1;i>=0;--i){
            ll v = A[i];
            for(auto af : b)v = min(v,v^af);
            if(v){
                if(s[i] == '1'){
                    cout << 1 << endl;
                    goto OUT;
                }
                b.push_back(v);
            }
        }
        cout << 0 << endl;
OUT:;
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

lint app() {
  int n;
  cin>>n;

  lint ec=0;
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--;v--;
    if(u>v) swap(u,v);
    ec+=(lint)(u+1)*(n-v);
  }

  lint nc=0;
  rep(i,n){
    nc+=(lint)(n-i+1)*(n-i)/2;
  }

  return nc-ec;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n; cin >> n; if (n == 0) break;
		vector<ll> I(n); for (int i = 0; i < n; i++) scanf("%lld", &I[i]);

		long double H = 1e19;
		vector<ll> ans(3, INF);
		for (int s = 0; s <= 15; s++)for (int a = 0; a <= 15; a++) for (int b = 0; b <= 15; b++) {
			int now = s;
			vector<int> cnt(256);
			for (int i = 0; i < n; i++) {
				now = (now * a + b) % 256;
				cnt[(now + I[i]) % 256]++;
			}
			long double tmp = 0;
			for (int i = 0; i <= 255; i++) {
				if(cnt[i] > 0) tmp -= (long double)cnt[i] / n * log10((long double)cnt[i] / n);
			}
			//cout << tmp << endl;
			if (tmp + 1e-14< H) {
			    H = tmp;
				ans[0] = s;
				ans[1] = a;
				ans[2] = b;
			}
			else if (abs(H - tmp) < 1e-14) {
				//cout << s << " " << a << " " << b << endl;
				chmin(ans, { s,a,b });
			}
		}
		cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n";
	}
	return 0;

}



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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      s[i].push_back(x);
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; ++i) cin >> p[i];
  int res = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool good = true;
    for (int j = 0; j < M; ++j) {
      int sum = 0;
      for (auto k : s[j]) {
        if ((i >> (k - 1)) & 1 == 1) sum++;
      }
      if (sum % 2 != p[j]) good = false;
    }
    if (good) res++;
  }
  cout << res << endl;
}

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

int main(){
  int N,score,number;
  string city;
  cin>>N;
  vector<tuple<string,int,int>> vec;
  for(int i=1;i<=N;i++){
    cin>>city>>score;
    score*=-1;
    vec.push_back(make_tuple(city,score,i));
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N;i++){
    tie(ignore,ignore,number)=vec.at(i);
    cout<<number<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int W;
  int H;
  int N;
  cin >>W>>H>>N;
  vector<int>x(N);
  vector<int>y(N);
  vector<int>a(N);
  
  rep(i,N) {
cin >>x.at(i)>>y.at(i)>>a.at(i);
  }
int data[H][W];
  rep(i,H) {
rep(j,W) {
  data[i][j]=0;
}
  }
  
  rep(k,N) {
   // cout<<a.at(k)<<endl;
    if(a.at(k)==1) {
               rep(j,x.at(k)) {
               rep(i,H) {
                 data[i][j]=1;
               }
               }
    }
    
    if(a.at(k)==2) {
               repl(j,x.at(k),W) {
               rep(i,H) {
                 data[i][j]=1;
               }
               }
    }
  
    if(a.at(k)==3) {
               rep(i,y.at(k)) {
               rep(j,W) {
                 data[i][j]=1;
               }
               }
    }
    
    
    if(a.at(k)==4) {
               repl(i,y.at(k),H) {
               rep(j,W) {
                 data[i][j]=1;
                 //cout<<"A"<<endl;
               }
               }
    }
  }
  int count=0;
  rep(i,H) {
rep(j,W) {
  if(data[i][j]==0){
    count++;
    //cout<<9898<<endl;
  }
}
  }
  
  cout<<count<<endl;
  }

Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
ab=[0]*(10**5+1)
n.times do
  a,b=gets.split.map(&:to_i)
  ab[a]+=b
end
c=0
i=0
ab.each do |b|
  c+=b
  if k<=c
    puts i
    exit
  end
  i+=1
end


Measured memory_bytes: 4604
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		while(true){
			int a = scanner.nextInt();
			String op = scanner.next();
			int b = scanner.nextInt();

			if(op.equals("+")){
				System.out.println(a + b);
			}else if(op.equals("-")){
				System.out.println(a - b);
			}else if(op.equals("*")){
				System.out.println(a * b);
			}else if(op.equals("/")){
				System.out.println(a / b);
			}else{
				break;
			}
		}
	}
}

Measured memory_bytes: 26260
#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<int> lk(q);
  vector<ll> memo(n, 0);
  for (int &k: lk) cin >> k;
  for (int k : lk) {
    ll ans = 0;
    vector<ll> ls(3, 0);
    for (int i = 0; i < n; ++i) {
      if (i >= k) {
        if (s[i-k] == 'D') {
          --ls[0];
          ls[2] -= ls[1];
        }
        if (s[i-k] == 'M') --ls[1];
      }
      if (s[i] == 'D') ++ls[0];
      if (s[i] == 'M') {
        ++ls[1];
        ls[2] += ls[0];
      }
      if (s[i] == 'C') {
        ans += ls[2];
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 9220
#include <stdio.h>

int main() {
	int n;//日数
	int m;//宿題数
	int a[10000];//必要日数
	int total = 0;//合計日数
	int play = 0;//遊べる日数
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &a[i]);
	}

	for (int j = 0; j < m; j++) {
		total += a[j];
	}
	play = n - total;
	if (play < 0) {
		printf("-1");
	}
	else printf("%d", play);

	return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 30

struct Node{
    int parent, left, right;
};
Node T[MAX];
int n;
void preorder(int u){
    if(u == NIL) return;
    printf(" %d", u);
    preorder(T[u].left);
    preorder(T[u].right);
}
void inorder(int u){
    if(u == NIL) return;
    inorder(T[u].left);
    printf(" %d", u);
    inorder(T[u].right);
}
void postorder(int u){
    if(u == NIL) return;
    postorder(T[u].left);
    postorder(T[u].right);
    printf(" %d", u);
}
int main(){
    cin >> n;
    int v, l, r, root;
    for(int i = 0; i < n; i++){
        T[i].parent = NIL;
    }
    for(int i = 0; i < n; i++){
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }
    for(int i = 0; i < n; i++){
        if(T[i].parent == NIL) root = i;
    }
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl << "Inorder" << endl;
    inorder(root);
    cout << endl << "Postorder" << endl;
    postorder(root);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3248
import math
# K = int(input())
# ans = 0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         for k in range(1,K+1):
#             ans+=math.gcd(i,math.gcd(j,k)) 
# print(ans)           


ans = 0
K = int(input())
dp = [[1] * 220 for i in range(220)] 
for i in range(1,K+1):
    for j in range(1,K+1):
        dp[i][j] = math.gcd(i,j)
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            a = dp[i][j]
            gcd = dp[a][k]
            if i == j == k:
                ans += gcd
            elif i != j != k:
                ans += gcd * 6
            else:
                ans += gcd * 3  
print(ans)


Measured memory_bytes: 9512
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		if(H%h==0) {
			if(W%w==0) {
				pw.println("No");
			} else {
				pw.println("Yes");
				int[] v = getArray(w);
				for(int i=0; i<H; i++) {
					for(int j=0; j<W; j++) {
						pw.print(v[j%w]);
						pw.print(j<W-1 ? " " : "\n");
					}
				}
			}
		} else {
			pw.println("Yes");
			int[] v = getArray(h);
			for(int i=0; i<H; i++) {
				for(int j=0; j<W; j++) {
					pw.print(v[i%h]);
					pw.print(j<W-1 ? " " : "\n");
				}
			}
		}
		
		sc.close();
		pw.close();
	}
	
	static int[] getArray(int N) {
		int BASE = 1000;
		
		int[] ans = new int[N];
		Arrays.fill(ans, BASE);
		ans[N-1] = -(BASE*(N-1)+1);
		
		return ans;
	}
}


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

int main() {
    int n;
    std::cin >> n;
    
    std::vector<int> A(n);
    for (int i = 0; i < n; i++) {
        std::cin >> A[i];
    }

    int m;
    std::cin >> m;
    
    std::vector<int> B(m);
    for (int i = 0; i < m; i++) {
        std::cin >> B[i];
    }

    std::cout << (int)std::includes(A.begin(), A.end(), B.begin(), B.end()) << std::endl;
}



Measured memory_bytes: 4356
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{  int i;
    char str[100];
  scanf("%s",str);
   for (i=0;i<strlen(str);i++) str[i]-='0';
   int min=0;
   for (i=0;i<strlen(str)-2;i++)
   {
       if (abs(str[i]*100+str[i+1]*10+str[i+2]-753)<abs(str[min]*100+str[min+1]*10+str[min+2]-753))
        min=i;
   }

   printf("%d",abs(str[min]*100+str[min+1]*10+str[min+2]-753));

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

static void
init_pos(int* a, int n)
{
	int k = 0;
	for (int i = 0; i < n; i++) {
		a[i] = k++;
	}
}

static bool
next_pos(int* a, int n)
{
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] >= 9 - (n-i-1)) {
			continue;
		} else {
			a[i] ++;
			int h = a[i] + 1;
			for (int k = i+1; k < n; k++) {
				a[k] = h ++;
			}
			return true;
		}
	}
	return false;
}

static int
check(int* a, int n, int s)
{
	int b = 0;
	for (int i = 0; i < n; i++) {
		b += a[i];
	}

	if (s == b) {
		return 1;
	} else {
		return 0;
	}
}

int
main(void)
{
	char line[80];

	int n, s;

	int a[10];
	
	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			break;
		}
		if (sscanf(line, "%d %d", &n, &s) != 2) {
			break;
		}

		if (n == 0 && s == 0) {
			break;
		}

		init_pos(a, n);

		int m = check(a, n, s);
		
		while (next_pos(a, n)) {
			m += check(a, n, s);
		}

		printf("%d\n", m);
	}

	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;
const int M = 1000000007;


typedef long long int ll;
vector<ll> fac(700001); //n!(mod M)
vector<ll> ifac(700001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<700000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}



int main(){
  int x,y;
  cin >> x >> y;
  long long int ans;
  if((x+y)%3 != 0) ans = 0;
  else if(y > 2*x || x > 2*y) ans = 0;
  else{
    int dev = abs(x-y);
    int move = (x+y)/3;
    //move C (move-dev)/2
    ans = comb(move,(move-dev)/2)%M;

  }
  cout << ans << endl;



}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int ans = 0;

    int x = 0;
    int y = 0;
    for(int i=0; i<s.size();i ++){
        if(i%2 == 0 && s[i] == '0') x++;
        else if(i%2 == 1 && s[i] == '1') y++;
    }

    int len = s.size();
    ans = min(x+y, len - x - y);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import scala.util.control.Breaks

object Main extends App{
    // Your code here!
    val b1 = new Breaks
    var hoge = new Hoge()
    var primeCnt = 0
    var isFirst = true
    var loopMax = 0
    var loopCnt = 0;
    b1.breakable {
        for(line <- io.Source.stdin.getLines()) {
            if(isFirst) {
                isFirst = false
                loopMax = line.toInt
            } else {
                if(hoge.isPrime(line.toInt)){
                    primeCnt = primeCnt+1
                }
                loopCnt = loopCnt+1
                if(loopMax <= loopCnt){
                    b1.break
                }
            }
        }
    }
    println(primeCnt)
}

class Hoge() {
    def isPrime(n: Int): Boolean = {
        if (n < 2 || (n > 2 && n % 2 == 0)){
            return false
        } else if (n == 2) {
            return true
        }
        @annotation.tailrec
        def loop(n: Int, m: Int): Boolean = {
            if (m * m > n) {
                return true
            } else if (n % m == 0) {
                return false
            } else {
                loop(n, m + 2)
            }
        }
        loop(n, 3)
    }
}



Measured memory_bytes: 48896
using System;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var k = Console.ReadLine();
			var s = Console.ReadLine();

			var num = int.Parse(k);

			if (s.Length > num)
			{
				s = s.Substring(0, num) + "...";
			}

			Console.WriteLine(s);
		}
	}
}


Measured memory_bytes: 27540
a = list(map(int, input().split()))
b,c,d,e,f = a
j = []
j.append(b*e + c*f)
j.append(e*2*d if e > f else f*2*d)
j.append(f*2*d + (e-f)*b if e > f else e*2*d + (f-e)*c)
print(min(j))

Measured memory_bytes: 3060
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)

#define mp make_pair
#define P pair<int,int>
#define ll __int64

int n,m,r;
int x[1000],y[1000];
int dp[1000][1000];

int main(){

while(cin>>m>>n,m||n){//mは横、nは縦
	rep(i,1000)rep(j,1000)dp[i][j]=0;
	rep(i,1000)x[i]=y[i]=0;	
	//m--;n--;
	
	cin>>r;
	rep(i,r){
	cin>>x[i]>>y[i];
	x[i]--;
	y[i]--;
	}

	dp[0][0]=1;
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(i+j==0)continue;
			bool f=1;
			for(int k=0;k<r;k++)if(x[k]==i&&y[k]==j)f=0;
			if(!f)continue;
			if(i==0)dp[i][j]+=dp[i][j-1];
			else if(j==0)dp[i][j]+=dp[i-1][j];
			else dp[i][j]+=dp[i-1][j]+dp[i][j-1];
		}
	}
	cout<<dp[m-1][n-1]<<endl;
}	
	return 0;
}


Measured memory_bytes: 7000
N = int(input())
a_list = list(map(int, input().split()))

for i in range(N-1):
    if a_list[i] <0 and a_list[i+1] < 0:
       a_list[i] *= -1
       a_list[i+1] *= -1

counter = 0
min_list = []
for i in range(N):
    if a_list[i] < 0:
        counter += 1
        min_list.append(a_list[i])

if counter % 2 == 0:
    abc = sum(min_list)
    abc *= -1
    ans = sum(a_list)
    print(ans + 2*abc)

if counter % 2 == 1:
    for i in range(N):
        if a_list[i] < 0:
            a_list[i] *= -1
    min_mun = min(a_list)
    ans = sum(a_list) - 2*min_mun
    print(ans)

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

int main() {
    int n, m, temp_val;
    int a, b;
    vector<vector<pair<int, int>>> persons;
    vector<pair<int, int>> temp;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> m;
        temp.clear();
        for(int j = 0; j < m; ++j){
            cin >> a >> b;
            temp.push_back(make_pair(b, a));
        }
        persons.push_back(temp);
    }
    
    int limit = pow(2, n), count, max_count = 0;
    vector<bool> truth_vals(n);
    bool found, lied;
    unordered_set<int> true_peeps, false_peeps;
    for(int i = 0; i < limit; ++i){
        temp_val = i;
        count = 0;
        found = true;
        true_peeps.clear();
        false_peeps.clear();
        for(int j = 0; j < n; ++j){
            if(temp_val % 2 == 1){
                truth_vals[j] = true; 
                ++count;
            }else{
                truth_vals[j] = false;
            }
            temp_val /= 2;
        }
        for(int j = 0; j < n; ++j){
            for(int k = 0; truth_vals[j] && k < persons[j].size(); ++k){
                if(persons[j][k].first == 0){
                    if(truth_vals[persons[j][k].second - 1] || true_peeps.find(persons[j][k].second) != true_peeps.end()){
                        found = false;
                        break;
                    }else{
                        false_peeps.insert(persons[j][k].second);
                    }
                }else if(persons[j][k].first == 1){
                    if(!truth_vals[persons[j][k].second - 1] || false_peeps.find(persons[j][k].second) != false_peeps.end()){
                        found = false;
                        break;
                    }else{
                        true_peeps.insert(persons[j][k].second);
                    }
                }
            }   
        }
        
        if(found){
            max_count = max(count, max_count);
        }
    }
    cout << max_count << "\n";
    
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll A, B;
  cin >> A >> B;
  ll tmp = 2*A-1;
  tmp=max(A+B, tmp);
  tmp=max(2*B-1, tmp);
  cout << tmp;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    long long a,b;
    cin >> a >> b;
    if(abs(a - b) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (a + b) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())

cand = set()
for d in range(15):
    for x in range(1,1000):
        y = x*(10**d)-1
        cand.add(y)
cand.remove(0)

cand = sorted(cand,reverse=True)

def S(n):
    x = 0
    while n:
        q,r = divmod(n,10)
        x += r
        n = q
    return x

answer = []
opt_S = 1
opt_N = cand[0]+1
for x in cand:
    s = S(x)
    if x*opt_S <= s * opt_N:
        answer.append(x)
        opt_S = s; opt_N = x

print('\n'.join(map(str,answer[::-1][:K])))

Measured memory_bytes: 4072
#import<cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",a);
#define m(a,b) a<b?a:b
int w,n,m,c[k],d[k],p[k];main(){s(&n)s(&m)r(n)s(d+i)r(m)s(c+i)r(n)p[i]=1e9;r(m*n)w=i%n,p[w]=m(p[w],p[w+1]+c[i/n]*d[n-w-1]);printf("%d\n",p[0]);}

Measured memory_bytes: 1036
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int nf[1'000'006];

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

    auto cnt = 0LL;
    for (auto a = 1; a <= n; a++) {
        auto b_max = n / a;
        if (a * b_max == n)
            b_max--;
        if (b_max < 1)
            continue;
        cnt += b_max;
    }


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


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

int n,ans,arr[100];

int main(){
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d",&arr[i]);
		for(int j = 0;j<i;j++){
			ans += arr[i]*arr[j];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256