akhauriyash/Code-Regression huggingface dataset:
# 解説を参考に作成


def solve():
    N, M = map(int, input().split())

    m = 0
    # 奇数の飛び
    oddN = M
    oddN += (oddN + 1) % 2
    for i in range(oddN // 2):
        print(i + 1, oddN - i)
        m += 1
        if m == M:
            return
    # 偶数の飛び
    for i in range(M):
        print(oddN + i + 1, M * 2 + 1 - i)
        m += 1
        if m == M:
            return


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9232
# -*- coding: utf-8 -*-

import collections
import math


class Vector2(collections.namedtuple("Vector2", ["x",  "y"])):

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector2(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vector2(self.x * scalar, self.y * scalar)

    def __neg__(self):
        return Vector2(-self.x, -self.y)

    def __pos__(self):
        return Vector2(+self.x, +self.y)

    def __abs__(self):  # norm
        return math.sqrt(float(self.x * self.x + self.y * self.y))

    def dot(self, other):  # dot product
        return self.x * other.x + self.y * other.y

    def cross(self, other):  # cross product
        return self.x * other.y - self.y * other.x


def getDistanceSP(segment, point):
    p = point
    p1, p2 = segment
    if (p2 - p1).dot(p - p1) < 0:
        return abs(p - p1)
    if (p1 - p2).dot(p - p2) < 0:
        return abs(p - p2)
    return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)


def getDistance(s1, s2):
    a, b = s1
    c, d = s2
    if intersect(s1, s2):  # intersect
        return 0
    return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b))


def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if a.cross(b) > 0:
        return 1  # COUNTER_CLOCKWISE
    elif a.cross(b) < 0:
        return -1  # CLOCKWISE
    elif a.dot(b) < 0:
        return 2  # ONLINE_BACK
    elif abs(a) < abs(b):
        return -2  # ONLINE_FRONT
    else:
        return 0  # ON_SEGMENT


def intersect(s1, s2):
    a, b = s1
    c, d = s2
    return ccw(a, b, c) * ccw(a, b, d) <= 0 and ccw(c, d, a) * ccw(c, d, b) <= 0


if __name__ == '__main__':

    n = int(input())

    for _ in range(n):
        l = list(map(int, input().split()))
        s1 = [Vector2(l[0], l[1]), Vector2(l[2], l[3])]
        s2 = [Vector2(l[4], l[5]), Vector2(l[6], l[7])]

        print(getDistance(s1, s2))



Measured memory_bytes: 6172
/*...................bismillahir rahmanir rahim.....................*/
/*
  author :
    Muhammad Najmul hasan Nayeem
    Sust Math 17
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
 
using namespace std;

#define m_p make_pair
#define PB push_back
#define eb emplace_back
#define FF first
#define SS second
#define MX5 100005
#define MX6 1000006
#define MOD 1000000007
#define in()({int a;scanf("%d",&a);a;})
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SC()({char a;scanf("%c",&a);a;})
#define SL()({long long a;scanf("%lld",&a);a;})
#define SD()({double a;scanf("%f",&a);a;})
#define nl '\n'
#define For(_,n) for(int i=_;i<=n;i++)
#define once "once upon a time\n"
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<string,string> PSS;
// typedef tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << "(" << a.FF << ", " << a.SS << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    out << "[";
    for(int i=0;i<v.size();i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
 
#define chk(a) cout<<(#a)<<" = "<<a<<endl;
#define chka(a,_) cout<<(#a)<<"["<<_<<"] = "<<a[_]<<"\n";

// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool Check(int n,int pos){ return (bool)(n & (1<<pos)); }
 
/*............start.............*/

void solve()
{
    int n;
    cin>>n;
    int x,y,z;
    int xx,yy,zz;
    x=y=z=-1;
    zz=yy=zz=-2;
    bool ok=false;
    for(int i=0;i<n;i++)
    {
        swap(x,y);
        swap(y,z);
        swap(xx,yy);
        swap(yy,zz);
        cin>>z>>zz;
        if(x==xx && y==yy && z==zz) ok=true;
    }
    if(ok) cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
    // clock_t time_start=clock();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        // cout<<"Case "<<kase<<": ";
        // printf("Case %d: ",kase );
        solve();
    }
    // clock_t time_end=clock();
    // cerr<<float((time_end-time_start)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const double pie = 3.14159265358979;

int main(){
   int n;
   cin >> n;
   string s;
   cin >> s;
   s += '##';
   int ans = 0;
   char c = s[0];
   for(int i = 0; i <= n; i++){
       while(c == s[i]) i++;
       ans++;
       c = s[i];
   }
   cout << ans << endl;
   return 0;
}


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

 int main(){

  int N;

  cin >> N;


 vector<int> V(N);
   for (int i = 0; i < N; i++) {
    cin >> V.at(i);
   }


  vector<int> C(N);
   for (int i = 0; i < N; i++) {
    cin >> C.at(i);
   }


  int X = 0;
  int Y = 0;

  for (int i = 0; i < N; i++) {
   if (C.at(i) < V.at(i)) { 
    X += V.at(i);
    Y += C.at(i);
   }

   else if (C.at(i) >= V.at(i)) {
    X = X;
    Y = Y;
   }
  }

  int ans = X - Y;

  cout << ans << endl;

 return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (v[i] <= c[i]) {
                continue;
            }
            max += v[i] - c[i];
        }
        System.out.println(max);
    }

}


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

int main () {

  int N;
  cin >> N;
  
  vector <int> num(N);
  for (int i = 0; i < N; i++) cin >> num.at(i); 
  
  int count1 = 0;
  int count2 = 0; 
  bool stop = true;
  
  while (stop){
   for (int i = 0; i < N; i++){
    if (num.at(i)%2 == 0){
      count1 ++;
      num.at(i) = num.at(i)/2;
    }
   }
    if (count1 == count2) stop = false;
    else count2 = count1;
  }
  cout << count1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

const int N = 305;
int n, k, mod;
int C[N][N], dp[N][N], sdp[N][N];

namespace MATHEMATICS {
	int add(int x, int y) {
		int ret = x + y;
		if (ret >= mod) ret -= mod;
		return ret;
	}
	int mi(int x, int y) {
		int ret = x - y;
		if (ret < 0) ret += mod;
		return ret;
	}
	
	void inc(int &x, int y) {
		x += y;
		if (x >= mod) x -= mod;
	}
	void dec(int &x, int y) {
		x -= y;
		if (x < 0) x += mod;
	}
	
	int mul(int x, int y) {
		return 1LL * x * y % mod;
	}
}
using namespace MATHEMATICS;

void prework() {
	int i, j;
	for (i = 0; i <= n; ++i) C[i][0] = C[i][i] = 1;
	for (i = 2; i <= n; ++i)
		for (j = 1; j < i; ++j)
			C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
}

void work() {
	int i, j, s, y;
	for (j = 0; j <= k; ++j) dp[1][j] = 1;
	for (j = k; ~j; --j) sdp[1][j] = add(sdp[1][j + 1], dp[1][j]);
	
	for (i = 2; i <= n + 1; ++i) {
		for (j = 0; j <= k; ++j)
			for (s = 1; s < i; ++s)
				inc(dp[i][j], mul(mul(dp[i - s][j], sdp[s][j + 1]), C[i - 2][s - 1]));
		for (j = k; ~j; --j) sdp[i][j] = add(sdp[i][j + 1], dp[i][j]);
	}
	
	printf("%d\n", dp[n + 1][0]);
}

int main() {
	scanf("%d%d%d", &n, &k, &mod);
	prework(); work();
	return 0;
}

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

#define REP(i,n) for(int i=0; i<n; i++)
#define INF 1e10
int main()
{
	int a[101],N,r;
	double dp[10001],b,v,e,f;

	while(cin >> N, N)
	{
		REP(i,N) cin >> a[i];
		cin >> b;
		cin >> r >> v >> e >> f;
		a[N]=-1;

		REP(i,10001) dp[i]=INF;

		int next=0;
		dp[0]=0;
		for(int i=0; i<a[N-1]; i++)
		{
			for(int j=i; j>=0; j--)
			{
				if(j>=r) dp[j+1]=dp[j]+1/(v-e*(j-r));
				else 	 dp[j+1]=dp[j]+1/(v-f*(r-j));
				
			}
			
			dp[0]=INF;

			if(i+1==a[next])
			{
				REP(j,i+2)				
					dp[0]=min(dp[j]+b, dp[0]);
				next++;
			}
		}
		double ans=INF;
		REP(i,a[N-1]+1) ans=min(ans, dp[i]);
		
		cout << setprecision(7) << setiosflags(ios::fixed);
		cout << ans << endl;
	}
}

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

int main(){


	int a,b,c,d;
	int x;		//??\??????
	unsigned sum = 0;		//???a,b,c,d???????¨?
	unsigned counter = 0;	//????????????
// ??°????????\??????????????????????´?????????????


	while ((scanf("%d", &x)) != EOF) {   
		if ((x < 1) || (x > 50)) {
            printf("?????????????????´??°????????\?????????????????????\n\a");
            continue;
		}
		
		for (a=0; a<=9; a++){
			for (b=0; b<=9; b++){
				for (c=0; c<=9; c++){
					for (d=0; d<=9; d++){
						sum = a+b+c+d;
						if ( sum == x){
							counter++;	//????¨???¨??\???????????????????????°??????????????¢??????
						} 
					}
				}
			}	
		}

		printf("%d\n",counter);
		counter = 0;	//????????????????????????
	}
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);
  int p[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  int q[n+1];
  for (int i = 0; i < n; i++) {
    q[p[i]] = i;
  }
  int count = 1;
  int max = 1;
  for (int i = 2; i <= n; i++) {
    if (q[i] > q[i-1]) {
      count++;
    } else {
      count = 1;
    }
    if (count > max) {
      max = count;
    }
  }
  printf("%d\n", n-max);

  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , m;
   cin >> n >> m;
   cout << (n == m ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
          String t = sc.next();
      	String[] s_arr = s.split("");
      	String[] t_arr = t.split("");
      	for(int i =0; i<s_arr.length;i++){
        	if(!s_arr[i].equals(t_arr[i])){
              System.out.println("No");
              return;
            }
        }
      if(s_arr.length == t_arr.length-1){
		System.out.println("Yes");
      }else{
          System.out.println("No");
      }
    }
  

}

Measured memory_bytes: 35712
n = int(input())
a = list(map(int,input().split()))
flag = 1
cnt = 0
while flag:
  flag = 0
  for i in range(len(a)):
    if i > 0 and a[i] < a[i-1]:
      a[i],a[i-1] = a[i-1],a[i]
      flag = 1
      cnt += 1
print(" ".join((str(i) for i in a)))
print(cnt)


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

long long fac(int n){
  if(n == 0) return n;
  long long ans = 1;
  for(int i = 1;i <= n;i++){
    ans *= i;
    ans %= 1000000000+7;
  }
  return ans;
}

int main() {
  int n,m;
  cin >> n >> m;
  long long ans,facn,facm;
  facn = fac(n);
  facm = fac(m);
  if(abs(n-m) == 0){
    ans = (2*facn*facm)%1000000007;
  }
  else if(abs(n-m) == 1){
    ans = (facn*facm)%1000000007;
  }
  else{
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> h >> w >> n;
	ll p = max(h, w);
	ll q = min(h, w);
	ll tmp = 0;
	ll res = 0;
	rep(i, q+1) {
		tmp = p * i;
		if (tmp >= n) {
			res = i;
			break;
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
   a.append(int(input()))
   b.append(0)

# 1: now, -1: visited, 0: none
b[0] = 1
now = 0
count = 0
while (b[1] != 1 and count <= n):
   next = a[now] - 1

   if (b[next] == -1):
      print(-1)
      exit()

   b[now] = -1
   b[next] = 1

   now = next
   count += 1

if (b[1] == 1):
   print(count)
else:
   print(-1)


Measured memory_bytes: 7856
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ll n,k;

     cin>>n>>k;

     if(n%k==0)
          cout<<0<<endl;
     else if(n<k)
     {
          if((n%k)<(k-n))
               cout<<n<<endl;
          else
               cout<<abs(n-k)<<endl;
     }
     else
     {
          n = n%k;
          cout<<k-n<<endl;
     }
}


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

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        int x1 = scanner.nextInt();
        int y1 = scanner.nextInt();
        int x2 = scanner.nextInt();
        int y2 = scanner.nextInt();
        int x3 = scanner.nextInt();
        int y3 = scanner.nextInt();
        double a = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        double b = Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
        double c = Math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
        double x = Math.max(Math.max(a,b),c)/(2+Math.max(Math.max(a,b),c)/(Math.abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/(a+b+c)));
        System.out.println(x);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

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

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

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

int n;

int main() {
  cin >> n;
  vector<int> d(n);
  rep (i, n) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  if (n % 2 == 0) {
    cout << d.at(n/2) - d.at(n/2 - 1) << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e9;
const ld PI = asin(1) * 2;

int a[3];

int main()
{
    FAST_IO;

    FOR(i, 0, 2) cin >> a[i];
    sort(a, a+3);

    bool ok = false;
    if (a[0] == a[1] && a[1] != a[2]) ok = true;
    if (a[1] == a[2] && a[1] != a[0]) ok = true;

    if (ok) cout<<"Yes";
    else cout <<"No";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

#define rep(i, n) for (int i = 0; i < (n); ++i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP

void	Main()
{
	int	n;
	cin >> n;
	ll	sum;
	sum = 0;
	rep(i, n)
	{
		int x;
		cin >> x;
		sum += (x - 1);
	}	
	cout << sum << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


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


int main()
{
	int W, H;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)
			break;
		for (int i = 0;i < H;i++) {
			for (int j = 0;j < W;j++) {
				if ((i + j) %2== 0)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  ll A,B;
  cin >> A >> B;
  ll ABGCD = __gcd(A,B);
  ll ans = 1;
  map<ll,ll> mp;
  mp[1] = 1;
  for(ll i = 2;;i++){
    if(ABGCD % i == 0){
      if(mp[i] == 0){
        mp[i] = 1;
        ans++;
      }
      ABGCD/=i;
      i=1;
    }
    else if(i * i > ABGCD){
      if(mp[ABGCD] == 0)ans++;
      break;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
n, x, m = gets.chomp.split(' ').map(&:to_i)

a = (0..(m + 1)).map { nil }
a[1] = x

h = { x => 1 }
b, d = nil, nil
(2..(m + 1)).each do |k|
  a[k] = (a[k - 1] * a[k - 1]) % m
  if h[a[k]]
    b = h[a[k]]
    d = k - b
    break
  end
  h[a[k]] = k
end

puts a[1, b].sum + a[b + 1, d].sum * ((n - b) / d) + a[b + 1, (n - b) % d].sum


Measured memory_bytes: 17372
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <math.h> 

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (i = 0; i < n; i++)
#define FOR(i, a, b) for (i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

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

int main()
{

    std::cin.tie(0);

    int n,a;
    cin >> n;
    vector<int> vec(n);

    for (int i = 0; i < n-1; i++)
    {
        cin >> a;
        vec[a-1] = vec[a-1]+1;
    }
    
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << endl;
    }    

    return 0;

}



Measured memory_bytes: 3988
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=110000;
int t[MAXN];
int main()
{
//	freopen("A.in", "r", stdin);
//	freopen("A.out", "w", stdout);
	int n, c, k;
	scanf("%d%d%d", &n, &c, &k);
	for (int i=1; i<=n; i++) scanf("%d", &t[i]);
	sort(t+1, t+n+1);
	int ans=0;
	for (int i=1, j; i<=n; i++, i=j)
	{
		ans++; j=i;
		for (int p=0; j<=n&&p<c&&t[i]+k>=t[j]; j++) p++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int n, k, x, y, sum;
    scanf("%d%d%d%d", &n, &k, &x, &y);
    if (n > k) {
        sum = x * k + (n - k) * y;
    } else {
        sum = x * n;
    }
    printf("%d\n", sum);
    return 0;
}


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

#define MAX_N 100000

using namespace std;

int main(void)
{
    int N;
    int A[3][MAX_N];
    cin >> N;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
        sort(A[i], A[i] + N);
    }
    long long d[MAX_N + 1]; // d[i] is the number of (j, k) s.t. i <= j and A[1][j] < A[2][k]
    d[N] = 0;
    for (int i = N - 1; i >= 0; i--) {
        d[i] = d[i + 1] + ((A[2] + N) - upper_bound(A[2], A[2] + N, A[1][i]));
        // cout << "d[" << i << "] = " << d[i] << endl;
    }
    long long answer = 0;
    for (int i = 0; i < N; i++) {
        int j = upper_bound(A[1], A[1] + N, A[0][i]) - A[1];
        answer += d[j];
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, a;
    cin >> n >> a;
    cout << n*n - a << endl;
}


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


int main() {
    int a,b;
    cin>>a>>b;
    if(a>b)rep(i,a)cout << b;else{
        rep(i,b)cout << a;
    }
}


Measured memory_bytes: 256
//https://blog.csdn.net/hesorchen
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 1000000007
int main()
{
    string a;
    cin>>a;
    int len =a.size();
    while(len--)
    cout<<'x';
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector <int> primes;

bool isPrime(const int &n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

void init() {
    int n = 32769;
    for (int i = 2; i <= n; i++) {
        if (isPrime(i)) primes.push_back(i);
    }
}

int main()
{
    init();
    int num, sum, diff;
    vector<int>::iterator it;
    for (;;) {
        scanf("%d", &num);
        if (num == 0) break;
        sum = 0;
        for (int i = 0; i < primes.size(); i++) {
            if (primes[i] > num/2) break;
            it = lower_bound(primes.begin(), primes.end(), num-primes[i]);
            if (it != primes.end() && *it == num - primes[i]) sum++;
        }
        printf("%d\n", sum);
    }
    return 0;
}



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

using namespace std;

unsigned long long killMonster(unsigned long long& H)
{
	if(H==0) return 0;
	int bits=(log10(H)/log10(2));
    return pow(2.0,bits+1.0)-1;
}

int main()
{
   unsigned long long H;
   cin>> H ;
   cout<< killMonster(H)<<endl;
  return 0;

}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 4) {
        switch(s[i]) {
            case '+':ans += 2;
            case '-':ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def read():
    return int(input())


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


def readmap():
    return map(int, input().split())


N, M = readmap()
cake = []
for _ in range(N):
    x, y, z = readmap()
    cake.append((x, y, z))

ans_candidate = []

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] + x[1] + x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] + x[1] - x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] - x[1] + x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] + x[1] + x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] - x[1] - x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] + x[1] - x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] - x[1] + x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] - x[1] - x[2], reverse=True)
for i in range(M):
    point0 += cake[i][0]
    point1 += cake[i][1]
    point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))

print(max(ans_candidate))


Measured memory_bytes: 3320
#include<iostream>
using namespace std;
int main()
{
  int x, n, k, m = 0;
  cin >> n >> k;
  for(int i = 0; i < n; i++)
  {
    cin >> x;
    m = 2 * min(x, k - x) + m;
  }
  cout << m;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int N=2e5+10;
int n,m,cnt;
struct node{
	int to,nex;
}e[N<<1];
int bgn[N],f[N],ans[N];
void add(int x,int y){
	e[++cnt]=(node){y,bgn[x]};bgn[x]=cnt;
}
void dfs(int x,int fa){
	ans[x]=ans[fa]+f[x];
	for(register int i=bgn[x];i;i=e[i].nex){
		int y=e[i].to;
		if(y==fa)continue;
		dfs(y,x);
	}
}
int main( ){
	int x,y,z,k;
	n=read( );m=read( );
	for(register int i=1;i<n;++i){
		x=read( );y=read( );
		add(x,y);add(y,x);
	}
	for(register int i=1;i<=m;++i){
		x=read( );y=read( );f[x]+=y;
	}
	dfs(1,0);
	for(register int i=1;i<=n;++i)
		printf("%d ",ans[i]);
	return 0;
}

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

int main()
{
 int n;
  cin >> n;
  
  for (int i = 1; i <= 9; i++)
    for (int j = 1; j<=9;j++)
      if (i*j == n)
      {
        cout << "Yes" << endl;
        exit(0);
      }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)

n, m = input().split(' ')
N = int(n)
M = int(m)

sorted_ab = sorted([list(map(int, input().split())) for i in range(N)])

# 報酬がi日後までにもらえるタスクの中(pool)で報酬が最大ものを選んでいく。
# 最大 M-1 回働ける
index = 0
pool = []
rewords = 0
for i in range(M):
    day = i + 1

    while index < N and day >= int(sorted_ab[index][0]):
        heappush(pool, -sorted_ab[index][1])
        index += 1
    # pool の中にある仕事の中から最大の報酬のものを選ぶ
    if pool:
        rewords += -heappop(pool)

print(rewords)


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

using namespace std;

#define endl '\n'

const int nax = 1e5 + 5;
int freq[nax];

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  long long sum = 0;

  for(int i=0;i<n;i++){
    long long x;
    cin >> x;
    sum += x;
    freq[x]++;
  }

  int q;
  cin >> q;

  while(q--){
    long long b,c;
    cin >> b >> c;
    long long elementsRemoved = freq[b];
    freq[b] = 0;
    sum = sum - elementsRemoved*b + elementsRemoved*c;
    freq[c] += elementsRemoved;
    cout << sum << endl;
  }
 
  return 0;
}

Measured memory_bytes: 4044
#include <iostream>

using namespace std;

const int DIM = 200010;

int n, q, i, p, u, m, st, dr, aux, b[DIM];
char s[DIM], a[DIM], c;

int calculeaza(int x) {
    for (i = 1; i <= q; ++i) {
        if (s[x] == a[i]) {
            x += b[i];
        }
        if (x == 0 || x == n + 1) {
            break;
        }
    }
    return x;
}

int main() {
    cin >> n >> q;
    cin >> s + 1;
    for (i = 1; i <= q; ++i) {
        cin >> a[i] >> c;
        if (c == 'L') {
            b[i] = -1;
        } else {
            b[i] = 1;
        }
    }

    p = 1;
    u = n;
    while (p <= u) {
        m = (p + u) >> 1;
        aux = calculeaza(m);
        if (aux == 0) {
            st = m;
            p = m + 1;
        } else {
            u = m - 1;
        }
    }

    p = 1;
    u = n;
    dr = n + 1;
    while (p <= u) {
        m = (p + u) >> 1;
        aux = calculeaza(m);
        if (aux == n + 1) {
            dr = m;
            u = m - 1;
        } else {
            p = m + 1;
        }
    }

    cout << dr - st - 1 << "\n";

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  bool nums[1001] = {false};

  nums[1] = true;
  for (int b = 2; b <= 32; ++b) {
    for (int e = 2; pow(b, e) <= 1000; ++e) {
      nums[(int)pow(b, e)] = true;
    }
  }
  double n;
  cin >> n;

  for (int i = n; i >= 1.0; --i) {
    if (nums[i]) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

char S[101010];
int main(){
scanf("%s",S);
bool app[26];
for(int i = 0; i < 26; i++){
    app[i] = false;
}
for(int i = 0; S[i] != '\0'; i++){
    app[S[i] - 'a']  = true;
}
for(int i = 0; i < 26; i++){
if(!app[i]){
printf("%c\n", (char)(i+'a'));
return 0;
}
}
puts("None");
return 0;

}

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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back

void solve(){
    int x, ans = 0;
    for(int i=1; i<=5; i++){
        cin >> x;
        if(x == 0) ans = i; 
    }
    cout << ans;
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int N;
int V[50];
int C[50];

int dfs(int index,int cost,int value) {
  if(index == N) {
    return value - cost;
  }
  return max(dfs(index+1,cost + C[index],value + V[index]), dfs(index+1,cost,value) );
}

int main() {
  cin >> N;
  rep(i,N) {
    cin >> V[i];
  }
  rep(i,N) {
    cin >> C[i];
  }
  int ans = dfs(0,0,0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<complex>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((abs(a-c)<=d)|((abs(a-b)<=d)&&(abs(b-c)<=d))){
      cout<< "Yes";
    }else{
      cout<< "No";
    }
    return 0;
   }


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

int main(){
    int N;
    cin >> N;
    
    if(N%2 == 0) cout << 1.0/2.0 << endl;
    else cout << (double)((double)(N + 1)/2.0)/(double)N << endl;
}


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

using namespace std;

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

  int e4 = 0;
  int e2 = 0;
  int o = 0;

  for (int i = 0; i < n; i++) {
    int tmp; cin >> tmp;
    if (tmp % 4 == 0) {
      e4 = e4 + 1;
    } else if (tmp % 2 == 0) {
      e2 = e2 + 1;
    } else {
      o = o + 1;
    }
  }
  if (e2 == 0) {
    if (e4 >= (o - 1)) {
      cout << "Yes" << endl;      
    } else {
      cout << "No" << endl;      
    } 
  }
  else {
    if (e4 >= o) {
      if (e4 >= (o)) {
        cout << "Yes" << endl;      
      }
      else {
        cout << "No" << endl;      
      } 
    } else {
      if (e4 >= (o + 1)) {
        cout << "Yes" << endl;      
      }
      else {
        cout << "No" << endl;      
      }
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;

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

  vector<vector<int>> connection(N);
  vector<int> counter(N);
  REP(n,N) counter[n] = 0;

  REP(n,N-1){
    int a, b;
    cin >> a >> b;
    a -=1, b-=1;
    connection[a].push_back(b);
    connection[b].push_back(a);
  }

  REP(q,Q){
    int p, x;
    cin >> p >> x;
    counter[p-1] += x;
  }

  deque<vector<int>> deq;

  REP(n0,connection[0].size()){
    vector<int> vec(2);
    vec[0] = 0;
    vec[1] = connection[0][n0];
    deq.push_back(vec);
    counter[vec[1]] += counter[0];
  }

  while(! deq.empty()){
    int parent, target;
    parent = deq[0][0];
    target = deq[0][1];
    deq.pop_front();

    REP(nt,connection[target].size()){
      int child = connection[target][nt];
      if (parent != child){
        counter[child] += counter[target];
        vector<int> vec(2);
        vec[0] = target;
        vec[1] = child;
        deq.push_back(vec);
      }
    }
  }

  REP(n,N) cout << counter[n] << " ";
  cout << endl;
}


Measured memory_bytes: 25844
#include<stdio.h>

int main(){
	int l, r, d;
	scanf("%d %d %d", &l, &r, &d);
	
	int ctr = 0;
	
	for(int i = l; i <= r; i++){
		if(i % d == 0){
			ctr++;
		}
	}
	printf("%d\n", ctr);
	return 0;
}

Measured memory_bytes: 1676
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int e[101][101];
	int R, C, r, c;
	int s, total;

	scanf("%d%d", &R, &C);
	for (r = 1; r <= R; r++) {
		for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
	}
	
	for (r = 1; r <= R; r++) {
		s = 0;
		for (c = 1; c <= C; c++) s += e[r][c];
		e[r][0] = s;
	}
	total = 0;
	for (c = 1; c <= C; c++) {
		s = 0;
		for (r = 1; r <= R; r++) s += e[r][c];
		e[0][c] = s;
		total += s;
	}
	for (r = 1; r <= R; r++) {
		for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
		printf("%d\n", e[r][0]);
	}
	for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
	printf("%d\n", total);
	return 0;
}



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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (k > a) {
      ans += a;
      k -= a;
      if (k > b) {
          k -= b;
          if (k <= c) {
              ans -= k;
          }
      }
  } else {
      ans = k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int ans = c - (a-b);
  cout << (ans>=0? ans : 0) << endl;
}

Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int Q=1<<17;
int link[Q],q[Q],hd=1,tl=0;
int pt[Q],vis[Q];
vector<int> g[Q];
bool Find(int x,int tim)
{
	if(vis[x]==tim)return 0;
	vis[x]=tim;
	for(int t=0;t<g[x].size();t++){
		int y=g[x][t];
		if((!link[y])||Find(link[y],tim)){
			link[y]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int tmp,x;
		scanf("%d",&tmp);
		while(tmp--)scanf("%d",&x),g[x].push_back(i);
	}
	for(int i=2;i<=n;i++)
		if(!Find(i,i))return puts("-1")&0;
	q[++tl]=1;
	for(int i=1;i<=n;i++){
		if(hd>tl)return puts("-1")&0;
		int x=q[hd++];
		for(int t=0;t<g[x].size();t++){
			int st=g[x][t];
			if(pt[st])continue;
			pt[st]=x;
			q[++tl]=link[st];
		}
	}
	for(int i=1;i<n;i++)
		printf("%d %d\n",min(pt[i],link[i]),max(pt[i],link[i]));
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define MAX 300
typedef pair<int,int> P;
 
class Dice{
private:
    int tmp;
public:
    int d[6];
 
    Dice(){
	rep(i,6){
	    d[i] = i+1;
	}
    } 
 
    void rollN(){
	tmp = d[0];
	d[0] = d[1];
	d[1] = d[5];
	d[5] = d[4];
	d[4] = tmp;
    }
   
    void rollE(){
	tmp = d[0];
	d[0] = d[3];
	d[3] = d[5];
	d[5] = d[2];
	d[2] = tmp;
    }
  
    void rollS(){
	tmp = d[0];
	d[0] = d[4];
	d[4] = d[5];
	d[5] = d[1];
	d[1] = tmp;
    }
  
    void rollW(){
	tmp = d[0];
	d[0] = d[2];
	d[2] = d[5];
	d[5] = d[3];
	d[3] = tmp;
    }
 
    void rotation(){
	tmp = d[1];
	d[1] = d[3];
	d[3] = d[4];
	d[4] = d[2];
	d[2] = tmp;
    }
 
    void change(int top,int front){
	rep(i,3){
	    rollN();
	    if(top == d[0]){
		break;
	    }
	    rollW();
	    if(top == d[0]){
		break;
	    }
	}
	rep(i,3){
	    if(front == d[1]){
		break;
	    }
	    rotation();
	}
    }
};
 
map<P,int> num;
int field[MAX][MAX];
 
void init(){
    num.clear();
    for(int i = 0 ; i < MAX ; i++){
	for(int j = 0 ; j < MAX ; j++){
	    field[i][j] = -1;
	}
    }
}
 
bool check(P a, P b){
    return num[a] > num[b];
}
 
int main(){
    int N;
    const int dx[] = {0,1,-1,0};
    const int dy[] = {1,0,0,-1};
    while(cin >> N, N){
	int t, f;
	Dice dice;
	init();
	rep(i,N){
	    int x = 150, y = 150;
	    cin >> t >> f;
	    dice.change(t, f);
	    if(i == 0){
		num[P(y,x)]++;
		field[y][x] = dice.d[0];
	    }else{
		while(true){
		    int pos = 0, max = 0;
		    for(int j = 1 ; j < 5 ; j++){
			if(dice.d[j] < 4) continue;
			int nx = x + dx[j-1];
			int ny = y + dy[j-1];
			if(max < dice.d[j] && check(P(y,x),P(ny,nx))){
			    max = std::max(max,dice.d[j]);
			    pos = j-1;
			}
		    }
		    if(max == 0){
			num[P(y,x)]++;
			field[y][x] = dice.d[0];
			break;
		    }
 
		    x += dx[pos];
		    y += dy[pos];
 
		    switch(pos){
		    case 0:
			dice.rollS();
			break;
		    case 1:
			dice.rollE();
			break;
		    case 2:
			dice.rollW();
			break;
		    case 3:
			dice.rollN();
			break;
		    }
		}
	    }
	}
	int cnt[6] = {0};
	rep(i,MAX){
	    rep(j,MAX){
		if(field[i][j] != -1){
		    cnt[field[i][j]-1]++;
		}
	    }
	}
	rep(i,6){
	    if(i == 5) cout << cnt[i] << endl;
	    else cout << cnt[i] << " ";
	}
    }
 
    return 0;
}

Measured memory_bytes: 3448
/**
 * Created by hiramekun at 20:50 on 2020-04-04.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */


void solve() {
    ll n, k;
    cin >> n >> k;
    cout << min(n % k, k - (n % k)) << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    ll a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

int main(){
    int N, H, max = 0, ans = 0;
    intscan(N);
    Ntimes(N){
        intscan(H);
        if(H>=max) {ans++; max = H;}
    }
    printans(ans);
    return 0;
}

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

int main()
{
    int N;
    string S;
    cin >> N >> S;
    if (N % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < N / 2; i++)
    {
        if (S[i] != S[i + N / 2])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int N=0;
  scanf("%d", &N);
  if(N %2 == 0){
    printf("%f\n", 0.5);}
  else{
    double a= N;
    printf("%f\n", (a+1)/(2*a));}
  return 0;
}


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

int d[300][300];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)rep(j, n)scanf("%1d", &d[i][j]);
		int Max = 0;
		rep(i, n)rep(j, n) {
			int cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; y++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++, y++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++, y--) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
		}
		printf("%d\n", Max);
	}
}

Measured memory_bytes: 3424