akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    using pld = pair<long double, long double>;
    vector<pld> engines(N);
    rep(i, N) { cin >> engines[i].first >> engines[i].second; }
    sort(All(engines), [](const auto &p1, const auto &p2) {
        return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first);
    });
    for(int i = 0; i < N; i++) {
        engines.pb(engines[i]);
    }
    long double res = 0;
    for(int l = 0; l < N; l++) {
        for(int r = l; r - l < N; r++) {
            long double dx = 0, dy = 0;
            for(int i = l; i <= r; i++) {
                dx += engines[i].first, dy += engines[i].second;
            }
            res = max(res, sqrt(dx * dx + dy * dy));
        }
    }
    cout << fixed << setprecision(20) << res << endl;
    return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll dp[110][10];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H,W,K;
    cin>>H>>W>>K;
    ll n[8]={1,1,2,3,5,8,13,21};
    rep(i,0,W){
        if(i==0) dp[0][i]=n[W-1];
        else if(i==1) dp[0][i]=n[W-2];
        else dp[0][i]=0;
    }
    rep(i,1,H){
        rep(j,0,W){
            if(j==0){
                dp[i][j]=(dp[i-1][j]*n[W-1]%MOD+dp[i-1][j+1]*n[W-2]%MOD)%MOD;
            }
            if(j==W-1){
                dp[i][j]=(dp[i-1][j]*n[W-1]%MOD+dp[i-1][j-1]*n[W-2]%MOD)%MOD;
            }
            else{
                dp[i][j]=(dp[i-1][j-1]*n[j-1]%MOD*n[W-j-1]%MOD+dp[i-1][j]*n[j]%MOD*n[W-j-1]%MOD+dp[i-1][j+1]*n[j]%MOD*n[W-j-2]%MOD)%MOD;
            }
        }
    }
    cout <<dp[H-1][K-1] <<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		
		String[] narray = n.split("");
		
		int sum = 0;
		for(String s:narray){
			sum += Integer.parseInt(s);
		}
		
		if(sum%9==0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		

	}
}

Measured memory_bytes: 65288
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define Jrep(j,n) for(int j=0;j<(n);j++)
#define Jreps(j,n) for(int j=1;j<=(n);j++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h,w;
  cin>>h>>w;
  long long sum[1010][1010]={};
  char x;
  sum[1][1]=1;
  reps(i,h){
      Jreps(j,w){
	  cin>>x;
	  if(x=='.'){
	      sum[i][j]+=(sum[i-1][j]+sum[i][j-1])%1000000007;
	  }
      }
  }
  cout<<sum[h][w]<<'\n';
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
  int N; cin>>N;
  vector <int> A(N+1);
  vector <int> B(N);
  ll cnt = 0;
  //ll a-0; ll b = 0;
  for(int i=0;i<N+1;i++) {cin>>A[i];}
  for(int i=0;i<N;i++) {cin>>B[i];}

  for(int i=0;i<N;i++){
    int b = B[i];
    int a1 = A[i], a2 = A[i+1];
    

    if(b < A[i]){cnt += b; A[i] -= b;continue;}

    if(b >= A[i]) {cnt += A[i]; b = b - A[i]; A[i]= 0;}

    if(b < A[i+1]) { cnt += b; A[i+1] -= b; continue;}

    if(b >= A[i+1]) {cnt +=A[i+1] ;A[i+1] = 0; }
    



  }
cout<<cnt<<endl;
  


  return 0; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple
ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if(n&1==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}

int main(){
  int x,t; cin >> x >> t;
  cout <<(x-t > 0? x-t : 0) << endl;
  return 0;
}


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

int n, a;
int b[100];
long long memo[60][60][3000];

long long dp(int i, int j, int num){
    if(i == n){
        if(j > 0 && num % j == 0 && num / j == a){
            return 1;
        }else{
            return 0;
        }
    }

    if(memo[i][j][num] != -1){
        return memo[i][j][num];
    }

    return memo[i][j][num] = dp(i+1, j, num) + dp(i+1, j+1, num+b[i]);
}

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

    for(int i = 0;i < n;i++){
        cin >> b[i];
    }

    memset(memo, -1, sizeof(memo));

    cout << dp(0, 0, 0) << endl;

    return 0;
}


Measured memory_bytes: 84608
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();
		
		int q = N / X;
		int r = N % X;
		int s;
		if(r == 0) {
			s = q * T;
		}
		else {
			s = (q + 1) * T;
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int parent[100005], sizee[100005];
void init(int n)
{
	for (int i = 0; i <= n; ++i) {
		sizee[i] = 1;
		parent[i] = i;
	}
}
int find_root(int current)
{
	int temp = current;
	while (current != parent[current]) {
		current = parent[parent[current]];
	}
	return parent[temp] = current;
}
void merge(int a, int b)
{
	if (a != b) {
		if (sizee[a] > sizee[b]) {
			parent[b] = a;
			sizee[a] += sizee[b];
		}
		else {
			parent[a] = b;
			sizee[b] += sizee[a];
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	init(n);
	while (m--) {
		int a, b, c;
		cin >> a >> b >> c;
		merge(find_root(a), find_root(b));
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += parent[i] == i? 1: 0;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
import qualified Data.Bits as B

data Action = HIT | HOMERUN | OUT deriving (Show , Read , Eq)
type OutNum = Int
type Base = Int
type Point = Int
type BasePoint = (Base , Point)

hit :: BasePoint -> BasePoint
hit (s , p) = (h `mod` 8 , h `div` 8 + p)
    where
        h = s * 2 + 1

homerun :: BasePoint -> BasePoint
homerun (s , p) = (0 , B.popCount s + 1 + p)

simulate :: OutNum -> BasePoint -> [Action] -> (Point , [Action])
simulate 3 (_ , p) xs = (p , xs)
simulate o bp (HIT:xs) = simulate o (hit bp) xs
simulate o bp (OUT:xs) = simulate (o + 1) bp xs
simulate o bp (HOMERUN:xs) = simulate o (homerun bp) xs
simulate _ bp [] = (snd bp , [])

loopSimulate :: [Action] -> IO ()
loopSimulate [] = return ()
loopSimulate xs = let (p , as) = simulate 0 (0 , 0) xs in print p >> loopSimulate as

main :: IO ()
main = getLine
    >> getContents
    >>= return . map (read :: String -> Action) . lines
    >>= loopSimulate

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  char before = s[0];
  for (int i=1; i<s.size(); i++){
    if (before != s[i]) ans++;
    before = s[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
// --------------
// Tejas Pandey  |
// 07 - 07 - 19  |
// ABC #133      |
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,d;
	cin >> n >> d;
	vector<int> po[n+1];
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < d;j++)
		{
			int k;
			cin >> k;
			po[i].push_back(k);
		}
	}
	int ans = 0;
	for(int i = 0;i < n-1;i++)
	for(int j = i+1;j < n;j++)
	{
		//cout << po[i][0] << "\n";
		ll ke = 0;
		for(int k = 0;k < d;k++)
		ke += pow(abs(po[i][k] - po[j][k]),2);
		double calc = sqrt(ke);
		if(ceil(calc) == floor(calc)) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
int prus(int X){
  int A=0;
  rep(i,1,X+1)
    A+=i;
  return A;
  }
signed main(){
  int a,b;
  cin>>a>>b;
  cout<<prus(b-a)-b;
  }


Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

fn main() {
    let (H, W) = read!(usize, usize);
    let A = read![String; H]
        .into_iter()
        .map(|s| s.chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();

    let mut dp = vec![vec![0; W]; H];
    dp[0][0] = 1_i64;

    for y in 0..H {
        for x in 0..W {
            if y + 1 < H && A[y + 1][x] == '.' {
                dp[y + 1][x] += dp[y][x];
                dp[y + 1][x] %= P;
            }

            if x + 1 < W && A[y][x + 1] == '.' {
                dp[y][x + 1] += dp[y][x];
                dp[y][x + 1] %= P;
            }
        }
    }

    println!("{}", dp[H - 1][W - 1]);
}


Measured memory_bytes: 16636
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int h,w;
int a[505][505],b[505][505];
char s[505][505];
int main () {
#ifndef ONLINE_JUDGE
//file("agc004c");
#endif
    h=read();
	w=read();
	F(i,1,h){
	   scanf("%s\n",s[i]+1);
	   F(j,1,w){
	      if(s[i][j]=='#')a[i][j]=b[i][j]=1;
	   }
	}
	F(i,1,h)a[i][1]=1,b[i][w]=1;
	F(i,1,h){
	  if(i%2==1){
	     F(j,1,w-1){
		    a[i][j]=1;
		 }
	  }
	  else{
	     F(j,2,w)b[i][j]=1;
	  }
	}
	F(i,1,h){
		F(j,1,w)printf("%c",a[i][j]?'#':'.');
		cout<<endl;
	}
	cout<<endl;
	F(i,1,h){
	  F(j,1,w)printf("%c",b[i][j]?'#':'.');
	  cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(){
  ll n,tmp;
  double mid;
  vector<ll> vec(0);
  cin >> n;
  rep(i,n){
    cin >> tmp;
    vec.push_back(tmp);
  }
  tmp=vec.at(0);
  sort(vec.begin(),vec.end());
  mid=(double)vec.at(n-1)/2.0;
  rep(i,n){
    if(mid-vec.at(i)>0){
      tmp=vec.at(i);
    }
    else{
      if(vec.at(i)<(2*mid-tmp)){
        tmp=vec.at(i);
      }
      break;
    }
  }
  cout << vec.at(n-1) << " " << tmp << endl;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x, t;
    cin >> n >> x >> t;
    int ans = ((n + x - 1) / x) * t;
    cout << ans << endl;
    return 0;
}

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

import math

def main():
    while True:
        n = int(input())
        if n==0:
            break
        scores=[]
        scores=list(map(int,input().split()))
        avg=sum(scores)/len(scores)
        datas=len(scores)
        tmp=0
        for score in scores:
            tmp+=(score-avg)**2
        print(math.sqrt(tmp/datas))

if __name__=="__main__":
    main()


Measured memory_bytes: 5692
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
#define N 50
int dis[N][N],vis[N][N],ans;
char s[N][N];
struct nade{
	int x,y;
};
queue<nade>que;
int n,m;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int spfa(int sx,int sy){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			dis[i][j]=1e9;
	dis[sx][sy]=0;
	que.push(nade{sx,sy});
	while(!que.empty()){
		nade now=que.front();
		que.pop();vis[now.x][now.y]=0;
		for(int i=0;i<4;i++){
			int x=now.x+dx[i],y=now.y+dy[i];
			if(x<1||y<1||x>n||y>m||s[x][y]=='#')continue;
			if(dis[x][y]>dis[now.x][now.y]+1){
				dis[x][y]=dis[now.x][now.y]+1;
				if(!vis[x][y]){
					vis[x][y]=1;
					que.push(nade{x,y});
				}
			}
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			sum=max(sum,dis[i][j]!=1e9?dis[i][j]:0);
	return sum;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='.')ans=max(ans,spfa(i,j));
	printf("%d\n",ans);
}

Measured memory_bytes: 3232
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist1 = [-1] * N
    dist1[0] = 0
    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist1[nv] == -1:
                dist1[nv] = dist1[v] + 1
                if nv != N - 1:
                    queue.append(nv)

    dist2 = [-1] * N
    dist2[N - 1] = 0
    queue = deque([N - 1])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist2[nv] == -1:
                dist2[nv] = dist2[v] + 1
                if nv != 0:
                    queue.append(nv)

    F = S = 0
    for i, (d1, d2) in enumerate(zip(dist1, dist2)):
        if i in (0, N - 1):
            continue
        if d1 == -1:
            S += 1
        elif d2 == -1:
            F += 1
        elif d1 <= d2:
            F += 1
        else:
            S += 1

    if F > S:
        print('Fennec')
    else:
        print('Snuke')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 114416
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  from math import factorial as f
  n,m = sorted(readInts())
  
  sa = m - n
  if sa >= 2:
    ans = 0
  else:
    ans = f(m) * f(n)
    if sa == 0:
      ans *= 2
  print(ans % mod)
if __name__ == '__main__':
  main()

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
const int mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int main(){
	int n; cin >> n;
	vector<int> a(n), b;
	for(int i = 0; i < n; i++) cin >> a[i];
	int ans = 1, len = 0;
	for(int i = 0; i < n; i++){
		b.push_back(a[i]);
		len++;
		while(!b.empty() && b.back() < 2 * len - 1){
			b.pop_back();
			ans = mul(ans, len);
			len--;
		}
	}
	while(!b.empty()){
		b.pop_back();
		ans = mul(ans, len);
		len--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define int         long long
    #define pb          push_back
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define INF         1e18
    const int N = 300 + 5, K = 501;

    void solve(){
        int n;
        cin>>n;
        if(n%1000 == 0) cout<<0<<endl;
        else {
            int x = n/1000 + 1;
            cout<<1000*x - n<<endl;
        }
    }

    int32_t main()
    {
        IOS;
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {       
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3636
#include<iostream>

int main(int argc, char const *argv[]) {
  int input;
  long power = 1;
  std::cin >> input;
  for(int i = 1; i <= input; ++i){
    power = (power * i ) % 1000000007;
  }
  std::cout << power << std::endl;
  return 0;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 147 (https://atcoder.jp/contests/abc147)
// Problem: E: Balanced Path (https://atcoder.jp/contests/abc147/tasks/abc147_e)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

template <class T, size_t... Is> struct arr_helper;
template <class T> struct arr_helper<T> { using type = T; };
template <class T, size_t I, size_t... Is>
struct arr_helper<T, I, Is...> { using type = array<typename arr_helper<T, Is...>::type, I>; };
template <class T, size_t... Is> using arr = typename arr_helper<T, Is...>::type;

constexpr int S = 6401;
arr<int, 80, 80> a, b;
arr<bool, 80, 80, S> dp;

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

    int h, w; cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];
    dp[0][0][abs(b[0][0] - a[0][0])] = true;
    rep(i, h) reps(j, i ? 0 : 1, w) {
        int d = abs(a[i][j] - b[i][j]);
        if (i) {
            rep(x, S)
                dp[i][j][x] |= dp[i-1][j][abs(x-d)];
            rep(x, S-d)
                dp[i][j][x] |= dp[i-1][j][x+d];
        }
        if (j) {
            rep(x, S)
                dp[i][j][x] |= dp[i][j-1][abs(x-d)];
            rep(x, S-d)
                dp[i][j][x] |= dp[i][j-1][x+d];
        }
    }

    int mn = S;
    rep(i, S) {
        if (dp[h - 1][w - 1][i]) {
            mn = i;
            break;
        }
    }

    cout << mn << '\n';
    return 0;
}

Measured memory_bytes: 40320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Long N = sc.nextLong();

		Long sum = (long)0;

		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				long tmp = gcd(i,j);
				for (int k = 1; k <= N; k++) {
					sum += gcd(tmp,k);
				}
			}
		}

		System.out.println(sum);
		sc.close();
	}

	private static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

}

Measured memory_bytes: 53140
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, K, Q;
    in >> N >> K >> Q;
    vector<ll> A(Q);
    vector<ll> P(N);
    REP(i, N){
        P[i] = 0;
    }
    REP(i, Q){
        in >> A[i];
        P[A[i]-1]++;
    }
    REP(i, N){
        if(P[i] > (Q-K)){
            out << "Yes" << endl;
        }else{
            out << "No"<< endl;
        }
    }


    

}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main(){
	int a=1,b,c,count=0;
	cin>>b;
	for(;count<b;count++){
		if(a%3==0||a%10==3){
			cout<<' '<<a;
		}else{
			for(c=a;c!=0;){
				c/=10;
				if(c%10==3){
					cout<<' '<<a;
					break;
				}
			}
		}
		a++;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    ll mod = 1000000007LL;
    ll N;
    cin >> N;
    UM<char, int> lst;
    for (char c = 'a'; c <= 'z'; c++)
        lst[c] = 0;
    char tmp;
    REP(i, N)
    {
        cin >> tmp;
        lst[tmp]++;
    }
    ll ans = 1;
    for (char c = 'a'; c <= 'z'; c++)
    {
        ans = ans * (lst[c] + 1) % mod;
    }

    cout << (ans + mod - 1) % mod << endl;
    //system("pause");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define EF else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;

    /*
    **  author : mahiman12
    **  created : 2020-05-10 17:30 
    */
    cin>>str;
    cin>>str1;
    ll len = str.length();
    if(str1.length()-str.length()!=1)
    {
        cout<<"No";
    }
    else
    {
        if(str1.substr(0, len)!=str)
        {
            cout<<"No";
        }
        else
        {
            cout<<"Yes";
        }
    }
}




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


int main() {

    int n, l, t;
    cin >> n >> l;
    int s = 0;
    int num = 100000;
    for (int i = 1; i <= n; ++i) {
        s += l+i-1;
        if (abs(l+i-1) < num) {
            num = abs(l+i-1);
            t = i;
        }
    }
    cout << s - (l+t-1) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		
		Scanner in = new Scanner(System.in);
		
				while(in.hasNext()){
				int a = in.nextInt();
				int b = in.nextInt();
				int c = a + b;
				String str = Integer.toString(c);
				System.out.println(str.length());
	
		}
	}
}

Measured memory_bytes: 20448
#include<bits/stdc++.h>
using namespace std;
int main() {
	vector<int>v;
	int n;
	cin>>n;
	int a[n+3];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n,greater<int>());
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
	    {
	    	v.push_back(a[i]);
	    	i++;
	    }
	    if(v.size()==2)
	    {
	    	cout<<1LL*v[0]*v[1];
	    	return 0;
	    }
	}
	cout<<"0";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  string s;
  cin >> s;
  
  ll ans = 700;
  for (int i = 0; i < 3; i++){
    if (s[i] == 'o')
      ans += 100;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  string S;
  long long int K;
  int ans = 1;
  cin >> S >> K;
  bool a = true;
  long long int A = S.size();
  A = min(K, A);
  for (int i = 0; i < A; i++) {
    if (S.at(i) == '1') continue;
    cout << S.at(i) << endl;
    a = false;
    break;
  }
  if (a) cout << 1 << endl;
}

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

int main(){
  int N, M;
  int a[110];
  multiset<int> st;
  cin >> N >> M;
  for(int i = 0; i < 2*M; i++){
    cin >> a[i];
    st.insert(a[i]);
  }
  for(int i = 0; i < N; i++)
    cout << st.count(i+1) << endl;
}


Measured memory_bytes: 256
#ABC084D
def main():
    import sys
    Q = int(sys.stdin.readline())
    LR = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    #print(LR)
    
    check = [1 for _ in range(10**5+1)]
    check[0], check[1] = 0, 0
    for i in range(2, 10**5+1):
        if check[i] ==0:
            continue
        elif check[i] ==1:
            for j in range(2*i, 10**5+1, i):
                check[j] =0
    check2 = check.copy()
    for i in range(2, 10**5+1):
        if check[i]==1:
            #print((i+1)/2, check[(i+1)//2])
            if (i+1)%2==0 and check[(i+1)//2] ==1:
                continue
            else:
                check2[i] = 0
    
    #累積和
    for i in range(1, 10**5+1):
        check2[i] = check2[i-1] + check2[i]
    #print(check2)
    for lr in LR:
        print(check2[lr[1]] - check2[lr[0]-1])
                


if __name__ =='__main__':
    main()

Measured memory_bytes: 21108
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  string sp,t;
  cin >> sp >> t;
  string s,str;
  int res=0,counter;
  reverse(sp.begin(),sp.end());
  reverse(t.begin(),t.end());
  string ans="UNRESTORABLE";
  bool found;
  rep(i,sp.size()-t.size()+1){
    found=false;
    s=sp;
    counter=0;
    rep(j,t.size()){
      if(sp[i+j]=='?'||sp[i+j]==t[j]){
          counter++;
      }
      s[i+j]=t[j];
    }
    //if(found) break;
    if(counter==t.size()){
      str=s;
      found=true;
      break;
    }
  }
  if(found){
    rep(i,s.size()){
      if(str[i]=='?')str[i]='a';
    }
    reverse(str.begin(),str.end());
    ans=str;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int min = 1000;
        for (int i = 0; i < s.length() - 2; i++) {
            int n = Integer.parseInt(s.substring(i, i + 3));
            min = Math.min(min, Math.abs(n - 753));
        }

        System.out.println(min);
    }

}


Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            arr[i] -= i + 1;
        }
        in.nextLine();
        Arrays.sort(arr);
        System.out.println(f(arr, arr[n / 2]));
    }

    private static long f(int[] arr, int median) {
        long res = 0;
        for (int value : arr) {
            res += Math.abs(value - median);
        }
        return res;
    }
}


Measured memory_bytes: 61180
a=->q{
puts"? "+q*" "
$>.flush
gets
}
I=[*1..2*N=gets.to_i]
f=a[I[0,N]]
l,r=0,N
f==a[I[m=(l+r)/2,N]]?l=m:r=m while r-l>1
x=I[r,N-1]
puts"! "+I.map{|i|
a[[i]+(x.index(i)?I-I[l,N+1]:x)][0]
}*""

Measured memory_bytes: 2636
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC121D
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = ReadLong - 1;
            if (A < 0) A = 0;
            var B = ReadLong;

            long aXor = xorSum(A);
            long bXor = xorSum(B);

            //Console.WriteLine(aXor);
            //Console.WriteLine(bXor);
            Console.WriteLine(bXor ^ aXor);
        }

        static public long xorSum(long a)
        {
            if (a % 2 == 0)
            {
                return a + (a / 2) % 2;
            }
            else
            {
                return (a / 2) % 2 == 0 ? 1 : 0;
            }
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()

using namespace std;

template <typename T>
class Mat
{
    vector<vector<T>> mat;
    int rows, columns;
public:
    Mat<T>(int r, int c) : rows(r), columns(c) {
        mat = vector<vector<T>>(rows, vector<T>(columns));
    }

    Mat<T>(initializer_list<initializer_list<T>> _mat) : rows(_mat.size()), columns(_mat.begin()->size()){
        mat = vector<vector<T>>(rows, vector<T>(columns));
        int i = 0;
        for (auto&& row : _mat) {
            copy(row.begin(), row.end(), mat[i++].begin());
        }
    }

    vector<T> &operator[](int m) {
        return mat[m];
    }

    vector<T> operator*(const vector<T> v) const {
        auto ret = vector<T>(rows);
        for (int m = 0; m < rows; m++) {
            T sum = 0;
            for (int n = 0; n < columns; n++) {
                sum += mat[m][n] * v[n];
            }
            ret[m] = sum;
        }
        return ret;
    }

    Mat<T> &t() {
        auto _mat = vector<vector<T>>(columns, vector<T>(rows));
        for (int m = 0; m < rows; m++) for (int n = 0; n < columns; n++) {
            _mat[n][m] = mat[m][n];
        }
        mat = _mat;
        swap(rows, columns);
        return *this;
    }
};

const vector<Mat<int>> Rot = {
    {{ 1, 0 }, { 0, 1 }},
    {{ 0, 1 }, { -1, 0 }},
    {{ -1, 0 }, { 0, -1 }},
    {{ 0, -1 }, { 1, 0 }}
};

void normalize(vector<int> &x, vector<int> &y)
{
    for (int i = x.size()-1; i >= 0; i--) {
        x[i] -= x[0], y[i] -= y[0];
    }

    int d = 0;
    if (y[1] > 0) d = 1;
    if (x[1] < 0) d = 2;
    if (y[1] < 0) d = 3;

    loop (x.size(), i) {
        auto a = Rot[d] * vector<int>({ x[i], y[i] });
        x[i] = a[0];
        y[i] = a[1];
    }
}

int main()
{
    while (1) {
        int n; cin >> n;
        if (!n) break;
        int m; cin >> m;
        vector<int> orig_x(m), orig_y(m);
        loop (m, i) cin >> orig_x[i] >> orig_y[i];
        normalize(orig_x, orig_y);

        loop (n, i) {
            cin >> m;
            vector<int> x(m), y(m);
            loop (m, j) cin >> x[j] >> y[j];
            normalize(x, y);

            loop (2, k) {
                if (orig_x == x && orig_y == y) {
                    cout << i + 1 << endl;
                    break;
                }

                reverse(all(x));
                reverse(all(y));
                normalize(x, y);
            }
        }
        cout << "+++++" << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
N = int(input())
S = list(input())

count = 1
count2 = 1

for i in range(N-1):
    if S[i] == S[i+1]:
        count2 += 1
    elif S[i] != S[i+1]:
        count += 1
if count2 == N:
    print(1)
else:
    print(count)

Measured memory_bytes: 4084
import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
    input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
detect_time = [0] * n
finish_time = [0] * n
is_visit = [False] * n
stack = []
time = 0

while(time < n*2):
    time += 1
    id = is_visit.index(False) + 1
    stack.append(id)
    is_visit[id-1] = True
    detect_time[id-1] = time
    while(len(stack) != 0):
        id = stack[-1]
        if len(input_line[id-1]) == 0:
            time += 1
            finish_time[stack.pop()-1] = time
        else:
            detect_id = input_line[id-1].pop(0)
            if is_visit[detect_id-1]:
                continue
            stack.append(detect_id)
            time += 1
            detect_time[detect_id-1] = time
            is_visit[detect_id-1] = True


for id in range(n):
    print('{0} {1} {2}'.format(id+1, detect_time[id], finish_time[id]))


Measured memory_bytes: 5620
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
*a, = map(int, input().split()) 

a = [ai >> 1 for ai in a]

import fractions
from functools import reduce

def getLCM(a, b):
    return a * b // fractions.gcd(a, b)

def f(x):
    cnt = 0
    while x%2 == 0:
        x //= 2
        cnt += 1
    return cnt

cnt = f(a[0])
for i in range(1, len(a)):
    if cnt != f(a[i]):
        print(0)
        break
else:
    lcm = reduce(lambda x, y: getLCM(x, y), a)
    ans = (m-lcm) // (lcm*2) + 1 if m >= lcm else 0
    print(ans)

Measured memory_bytes: 83296
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <queue>
#include <map>
using namespace std;

int grid[15][10005];
int r,c;
int res=1e9;

void change(int row){
    for(int j=0;j<c;j++){
        if(grid[row][j]==1){
            grid[row][j]=0;
        }else{
            grid[row][j]=1;
        }
    }
}

int count(){
    int bad=0,col_bad=0;
    for(int j=0;j<c;j++){
        col_bad=0;
        for(int i=0;i<r;i++){
            if(grid[i][j]==1){
                col_bad++;
            }
        }
        bad+=min(col_bad,r-col_bad);
        if(bad>res){
            return bad;
        }
    }
    return bad;
}

void dfs(int row){
    if(row==r){
        int bad=count();
        res=min(res,bad);
        return;
    }

    dfs(row+1);

    change(row);
    dfs(row+1);
    change(row);


}


int main(){
    while(true){
        cin>>r>>c;
        res=1e9;
        if(r==0&&c==0) break;

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                cin >> grid[i][j];
            }
        }

        dfs(0);
        cout<<r*c-res<<endl;
    }

    return 0;
}


Measured memory_bytes: 3496
n = int(input())
a = input()

if "2" in a:
	ans = 0
	for i in range(n):
		if a[i] == "2":
			ans ^= ((n-1) == ( i | (n-1 - i)))
	if ans:
		print(1)
	else:
		print(0)

else:
	ans = 0
	for i in range(n):
		if a[i] == "3":
			ans ^= ((n-1) == ( i | (n-1 - i)))
	if ans:
		print(2)
	else:
		print(0)

Measured memory_bytes: 5612
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto Y = RD!long;
	long r1 = (Y % 5000) / 1000;
	long r5 = (Y % 10000) / 5000;
	long r10 = Y / 10000;

	while (r1 + r5 + r10 < N)
	{
		if (r1 + r5 + r10 + 4 <= N && r5 > 0)
		{
			--r5;
			r1 += 5;
		}
		else if (r10 > 0)
		{
			--r10;
			r5 += 2;
		}
		else break;
	}
	if (r1 + r5 + r10 != N)
	{
		writeln("-1 -1 -1");
	}
	else
	{
		writeln(r10, " ", r5, " ", r1);
	}

	stdout.flush();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


ll dp[50];

int main(){
    int n; cin >> n;
    dp[0] = 1;
    dp[1] = 1;
    rep(i, n){
        dp[i + 2] = dp[i + 1] + dp[i];
    }
    cout << dp[n] << endl;
    return 0;
}


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

int n;
int a[55];

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

Measured memory_bytes: 256
#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>;

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

int main(){
	int n;
	cin >> n;
    ll ns;
    vector<ll> n0(61);
    vector<ll> n1(61);
    rep(i, 61){
      n0.at(i) = 0;
      n1.at(i) = 0;
    }
    rep(i, n){
      cin >> ns;
      rep(j, 61){
        if(ns % 2 == 0){
          n0.at(j)++;
        }else{
          n1.at(j)++;
        }
        ns /= 2;
      }
    }
    ll a = 0;
    ll b = 0;
    rep(i, 61){
      b = n0.at(i) * n1.at(i);
      if(b >= 1000000007) b %= 1000000007;
      b = b * modpow(2, i);
      if(b >= 1000000007) b %= 1000000007;
      a += b;
      if(a >= 1000000007) a %= 1000000007;
    }
	cout << a << endl;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

a1=int((a-1)/10)+1
b1=int((b-1)/10)+1
c1=int((c-1)/10)+1
d1=int((d-1)/10)+1
e1=int((e-1)/10)+1

min = min((a-1)%10,(b-1)%10,(c-1)%10,(d-1)%10,(e-1)%10)
  
def time():
  
  return(a1*10+b1*10+c1*10+d1*10+e1*10+min-9)
  

print(time())

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == b && b == c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }    
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  int l,r;
  rep(i,s.size()){
    if(s.at(i)=='A'){
      l=i;
      break;
    }
  }
  rep(i,s.size()){
    if(s.at(s.size()-i-1)=='Z'){
      r=s.size()-i-1;
      break;
    }
  }
  cout << r-l+1 << endl;
}


Measured memory_bytes: 640