akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 約数の列挙O(√n)
vector<long long> divisor(long long n) {
	vector<long long> res;
	for (long long i = 1; i * i <= n; i++) {
  	if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

int main(){	
	long long N;
	long long M;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> v = divisor(M);
	sort(v.begin(), v.end());
	long long res = 1;
	for (int i=0; i<(int)v.size(); i++) {
		if (M/v[i] >= N) res = v[i];
	}

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



Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
if n==1:print(0);exit()
A=[A[i]-i-1 for i in range(n)]
B=sorted(A)

#print(B)

if n%2==1:
    d=B[n//2]
    print(sum([abs(A[i]-d) for i in range(n)]))
    exit()

ans=0
d=(B[n//2-1]+B[n//2])//2
print(sum([abs(A[i]-d) for i in range(n)]))


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

int main(){
  while(1){
    long long n,m;
    cin>>n>>m;
    if(!n&&!m)break;
    string ans;
    long long c=1,d=1;
    n--;
    while(n-9*c*d>=0) n-=9*c*d,c++,d*=10;

    d=n/c+d;
    while((int)ans.size()<m+n%c+10){
      long long t=d;
      string a;
      while(t)a+=(t%10+'0'),t/=10;
      reverse(a.begin(),a.end());
      ans+=a;
      d++;
    }
    for(int i=n%c;i<m+n%c;i++) cout <<ans[i];
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	vector<int> v;

	int V[N];
	int C[N];
	rep(i, N)
	{
		cin >> V[i];
	}

	rep(i, N)
	{
		cin >>C[i];
	}
	
	rep(i, N)
	{
		v.pb(V[i] - C[i]);
	}


	sort(v.rbegin(), v.rend());

	int total = 0;
	rep(i, N)
	{
		if (v[i] <= 0)
		{
			break; 
		}
		total += v[i];
	}

	cout << total << endl;
	return 0;
}


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

using namespace std;


#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)

const int MOD = 1000000007;



int main(){
    ll a,b,c;
    double f,d,e;
    cin >> a >> b >> c;
    if( c-a-b>0 && (c-a-b)*(c-a-b) > 4*a*b ) {
        cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
            }
    
    

    
    

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
ll n, k, s[100010] = {}, r;
int main() {
  cin >> n >> k;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    s[a] += b;
  }
  rep(i, 100010) {
    r += s[i];
    if (r >= k) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

int A[100000], n;

int binarySearch (int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right
        ) / 2;
        if  (A[mid] == key) return 1;
        if (key < A[mid]) right = mid;
        else if (key > A[mid]) left = mid + 1;
    }
    return 0;
    
}

int main(void){
    int q, k, sum = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &k);
        if (binarySearch( k ) ) sum++;
    }
    printf("%d\n", sum);

    return 0;
}



Measured memory_bytes: 3012
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 2019LL;

// extgcd (ax + by = gcd(a,b) を満たすx,yを求める)
// xとyで参照を使用している
// (実引数で指定した変数の中身が関数によって書き換わる)
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if(b!=0) {
        d = extgcd(b, a%b, y, x);
        y -= (a / b) * x;
    }
    else {
        x = 1; y = 0;
    }
    return d;
}

int main() {
    string s; cin >> s;
    int N = s.size();
    vector<int> invs(N+1, 1);

    int inv10;
    {
        int x, y;
        extgcd(10, MOD, x, y);
        inv10 = x;
        // cerr << inv10 << endl;
    }

    for(int i=1; i<=N; i++) {
        invs[i] = (invs[i-1] * inv10) % MOD;
    }

    vector<int> cnt(MOD);
    cnt[0] = 1;
    int val = 0; ll ans = 0;
    for(int i=0; i<N; i++) {
        val = (val * 10 + s[i] - '0') % MOD;
        int mul = val * invs[i+1] % MOD;
        ans += cnt[mul];
        cnt[mul]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4364
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        
        if(n==0)
        {
            System.out.println(0);
        }
        else
        {
        System.out.println(a[n-1]-a[0]);
        }
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>
using namespace std;
int acu(int a,int b,int c,int x){
    int y=a*x;
    y+=b;
    y=y%c;
    return y;
}
int main(void){
    int n,a,b,c,x;
while(1){
cin>>n>>a>>b>>c>>x;
if(n==0)break;
vector<int> y(n+1);
y[0]=x;
for(int i=0;i<n;i++)
cin>>y[i+1];
int ans=0;
int mem;
for(int i=1;i<=n;i++){
mem=y[i-1];
while(y[i]!=mem||i!=1){
    mem=acu(a,b,c,mem);
    ans++;
    if(ans>10000){
        ans=-1;
         break;
    }
    if(y[i]==mem)break;
}
if(ans==-1)break;
}
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int count = 0;
    for (int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(500*i+100*j+50*k == X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
N, A, B = map(int, input().split())

sum = 0
for i in range(1, N+1) :
  d = 0
  s = str(i)
  for j in range(len(s)) :
    d += int(s[j])
  if A <= d <= B :
    sum += i
    
print (sum)


Measured memory_bytes: 40176
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

bool comp(tuple<string, int, int> &a,tuple<string, int, int> &b ) {
    if(get<0>(a) != get<0>(b)) return get<0>(a) < get<0>(b);
    else return get<1>(a) > get<1>(b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  tuple<string, int, int> pp[110];
  rep(i, N) {
      string s; int p; cin >> s >> p;
    get<0>(pp[i]) = s; get<1>(pp[i]) = p; get<2>(pp[i]) = i + 1;
  }
  sort(pp, pp + N, comp);
  rep(i, N) {
      cout << get<2>(pp[i]) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100
using namespace std;

int A[MAX][MAX] = {0};
int color[MAX] = {0};
int f[MAX] = {0};
int d[MAX] = {0};
int time = 0;
int n;
stack<int> S;

int next(int u)
{
	for(int i=0; i<n; i++)
	{
		if(A[u][i])
		{
			if(color[i] == WHITE)
				return i;
		}
	}
	return -1;
}

void dfs(int u)
{
	S.push(u);
	color[u] = GRAY;
	d[u] = ++time;
	while(!S.empty())
	{
		int v = S.top();
		int x = next(v);
		if(x!=-1 && x!= v)
		{
			color[x] = GRAY;
			S.push(x);
			d[x] = ++time;
		}
		else
		{
			S.pop();
			color[v] = BLACK;
			f[v] = ++time;
		}
	}
}

int main()
{
	int u,k,v;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		scanf("%d%d", &u, &k);
		for(int j=0; j<k; j++)
		{
			scanf("%d", &v);
			A[u-1][v-1] = 1;
			//A[v-1][u-1] = 1;
		}
	}

	for(int i=0; i<n; i++)
	{
		if(color[i] == WHITE)
			dfs(i);
	}
	for(int i=0; i<n; i++)
	{
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}

	return 0;
}






Measured memory_bytes: 2752
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

int n, t, s;
int a[3456], b[3456];

int memo[3456][3456];
//(1indexed)i??????????±???°??§????????§????????????j
const int INF = INT_MAX / 4;
int dp(int i, int j)
{
	if (j < 0)return -INF;
	if (i == 0)return 0;
	if (memo[i][j] >= 0)return memo[i][j];
	int ans = dp(i, j - 1);
	if (!(j - b[i - 1] < s && s < j))
	{
		ans = max(ans, dp(i - 1, j - b[i - 1]) + a[i - 1]);
	}
	ans = max(ans, dp(i - 1, j));
	return memo[i][j] = ans;
}

int main(void)
{
	memset(memo, 0xff, sizeof(memo));
	scanf("%d %d %d", &n, &t, &s);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", a + i, b + i);
	}
	printf("%d\n", dp(n, t));
	return 0;
}

Measured memory_bytes: 50168
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]

ans = 0

for i in range(N):
    ANS = []
    for j in range(M):
        ANS.append(A[i][j] * B[j])
    if sum(ANS)+C > 0:
       ans += 1

print(ans)

Measured memory_bytes: 3064
import scala.io.StdIn.readLine

class Dice(val d:Array[Int]) {

  def roll(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def getTopFace(a:Array[Int]):Array[Int] = a.map(d)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = new Dice(faces)
  val rolls = readLine.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => dice.roll(y).map(x) }

  println(dice.getTopFace(rolls)(0))
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)

for i in range(N-1):
    if S[i] == S[i+1]:
        print(i+1, i+2)
        exit()

for i in range(N-2):
    if S[i] == S[i+2]:
        print(i+1, i+3)
        exit()

print(-1, -1)


Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;


int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int ans=0;

    while(n>0)
    {
        n=n/k;
        ans=ans+1;
    }
    
    printf("%d\n",ans);


    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  map<string, int> list;
  FOR(i, N) {
    cin >> s[i];
    sort(ALL(s[i]));
    list[s[i]]++;
  }
  ll ans = 0;
  for (pair<string, int> p : list) {
    ans += p.second * (ll)(p.second - 1) / 2;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define d(x) cerr << #x << ":" << x << endl;
#define da(x) cerr << #x << ":\n"; for(auto i: x) cerr << i << " ";cout << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	int n;
	cin >> n;
	if(n%1000)
	cout << (n/1000 + 1) * 1000 - n << "\n";
	else
	cout << 0 << "\n";
	return 0;
}


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

int main(){
    int n,m;
    //cout<<endl;
    while(1){
        cin>>n;
        char ch[1000001];
        if(n==0) break;
        cin>>m;
        for(int i=0; i<m; i++) cin>>ch[i];
        int cnt=0,pre=0,ans=0;
        for(int i=2; i<m; i++){
            if(ch[i]=='I'&&ch[i-1]=='O'&&ch[i-2]=='I'){
                if(pre+2==i) cnt++;
                else cnt=1;
                pre=i;
                /*cout<<"i=="<<i<<endl;
                cout<<"cnt=="<<cnt<<endl;*/
                if(cnt>=n) ans++;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int D,G;
    cin >>D>>G;
    vector<int> p(D);
    vector<int> c(D);
    for(int i = 0; i<D; i++) cin >> p[i] >> c[i];

    int ans=10000000;
    for(int i = 0; i < (1 << D); i++) {
        int cnt = 0;
        int sum = 0;
        int rest_max = 1;
        for(int j = 0; j < D; j++) {
            if(i & 1 << j) {
                cnt += 100* (j + 1) * p[j] + c[j];
                sum += p[j];
            } else {
                rest_max = j;
            }
        }
        if(cnt < G){
            int s1=100*(rest_max+1);
            int need = (G - cnt + s1 - 1) / s1;
            if(need > p[rest_max]){
                continue;
        }
        sum += need;
        }
        ans = min(ans,sum);
    }
    cout << ans;
}

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

int n,p[20],cnt=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=1;i<n-1;i++){
		if((p[i-1] < p[i] && p[i+1] > p[i]) || (p[i-1] > p[i] && p[i+1] < p[i]))
			cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    stack<int> st;
    stack<char> now;
    string s;
    while(!st.empty()) st.pop();
    while(!now.empty() ) now.pop();
    rep(i,n){
      cin>>s;
      int level=0;
      rep(j,s.size() ){
	if(s[j]=='.') level++;
      }
      while(st.size() >level){
	int num=st.top();
	st.pop();
	now.pop();
	if(now.top() == '+') st.top()+=num;
	else st.top()*=num;
      }
      if(isdigit(s[s.size() - 1])){
	if(now.empty() ){
	  st.push(s[s.size() - 1]-'0');
	}else{
	  if(now.top()=='+'){
	    st.top()+=s[s.size() - 1]-'0';
	  }else{
	    st.top()*=s[s.size() - 1]-'0';
	  }
	}
      }else{
	if(s[s.size() - 1]=='+'){
	  now.push('+');
	  st.push(0);
	  // cout<<'a'<<endl;
	}else{
	  now.push('*');
	  st.push(1);
	}
      }
    }
    while(st.size() != 1){
      int num=st.top();
      st.pop();
      now.pop();
      if(now.top() == '+') st.top()+=num;
      else st.top()*=num;
    }
    cout<<st.top()<<endl;
  }
     
      
  return 0;
}



Measured memory_bytes: 3172
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;


#define INF (1ll<<60)
int main(int argc, char const *argv[]) {
  int a,b;
  // cin>>a>>b;
  string s,t;cin>>s>>t;
  a=s.length();
  b=t.length();
  vector<long long> mems(a+1),memt(b+1);
  // mems[0]=(s[0]=='A'?1:-1);
  // memt[0]=(t[0]=='A'?1:-1);
  for(int i=0;i<a;i++)mems[i+1]=mems[i]+(s[i]=='A'?1:-1);
  for(int i=0;i<b;i++)memt[i+1]=memt[i]+(t[i]=='A'?1:-1);
  int q;cin>>q;
  while(q--){
    int x,y,z,w;cin>>x>>y>>z>>w;
    x--;y--;z--;w--;
    bool yes=(mems[y+1]-mems[x]-memt[w+1]+memt[z])%3==0;
    if(yes)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    // cout<<((mems[y+1]-mems[x]-memt[w+1]+memt[z])%3==0:"YES":"NO")<<endl;
  }
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ;
  cin >> N;
  
  int ans = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r ;
    int n = r - l +1;
    ans += n;
  }
 cout << ans << endl;
}


Measured memory_bytes: 3572
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}

module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
import Data.Fixed

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

readIntV :: Int -> IO (UV.Vector Int)
readIntV n = GV.unfoldrN n (fmap (fmap BC.tail) . BC.readInt) <$> BC.getLine

readIntegersV :: Int -> IO (V.Vector Integer)
readIntegersV n = GV.unfoldrN n (fmap (fmap BC.tail) . BC.readInteger) <$> BC.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BC.readInteger) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las


main :: IO ()
main =
  getLine >>= putStrLn . take 3


Measured memory_bytes: 4112
a=int(input())
b=int(input())
c=int(input())
x=int(input())
l=[]
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      l.append([i,j,k])
c=0
for item in l:
  v=item[0]*500+item[1]*100+item[2]*50
  if v==x:
    c+=1
print(c)

Measured memory_bytes: 16500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String solve = solve(a, b);
        System.out.println(solve);
    }

    public static String solve(int a, int b) {
        int multi = a * b;
        if (multi % 2 == 1) {
            return "Odd";
        }
        return "Even";
    }

}

Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = [list(input()) for _ in range(n)]
    B = [list(input()) for _ in range(m)]

    for i in range(n - m + 1):
        for j in range(n - m + 1):
            for k in range(m):
                for l in range(m):
                    if A[i + k][j + l] != B[k][l]:
                        break
                else:
                    continue
                break
            else:
                print("Yes")
                exit()
    else:
        print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[2020];
int len,x1,y1,x2,y2;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	for (int i=1;i<=len;++i)
	{
		if (s[i]=='N') ++y1;
		if (s[i]=='S') ++y2;
		if (s[i]=='W') ++x1;
		if (s[i]=='E') ++x2;
	}
	if ((y1*y2==0 && y1+y2!=0) || (x1*x2==0 && x1+x2!=0))
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
class JudgeStatusSummary
  def initialize(ars)
    @ars = ars
    @hs = {"AC" => 0, "WA" => 0, "TLE" => 0, "RE" => 0}
  end

  def solve
    @ars.each do |s|
      @hs[s] += 1
    end
    
    ["AC", "WA", "TLE", "RE"].each do |s|
      puts "#{s} x #{@hs[s]}"
    end
  end
end

def run
  n = gets.chomp.to_i
  ars = (0...n).each_with_object(Array.new(n)) do |i, a|
    a[i] = gets.chomp
  end
  
  JudgeStatusSummary.new(ars).solve
end

run



Measured memory_bytes: 20632
#include<stdio.h>
#include<iostream>
using namespace std;

int  N;
int main (){
    cin >> N;
    int ans = 0;
    for(int i=1; i<=N; i++){
        int cnt = 0;
        for(int j=1; j<=i; j++){
            if( i % j == 0 ) cnt++;
        }
        if(i % 2 && cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

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



int main(){
    int k;
    cin >> k;
    long ans = 0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans += gcd(i,gcd(j,l));
            }
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
	int a[9] = {};
	for (int i = 0; i < 9; ++i)
		cin >> a[i];
	int n, b;
	cin >> n;
	for (int j = 0; j < n; ++j)
	{
		cin >> b;
		for (int i = 0; i < 9; ++i)
		{
			if (a[i] == b)
			{
				a[i] = 0;
				break;
			}
		}
	}

	bool ans = false;
	for (int i = 0; i < 3; ++i)
	{
		if (a[3 * i] == 0 && a[3 * i + 1] == 0 && a[3 * i + 2] == 0)
			ans = true;
		if (a[i] == 0 && a[i + 3] == 0 && a[i + 6] == 0)
			ans = true;
	}
	ans = ans || (a[0] == 0 && a[4] == 0 && a[8] == 0) || (a[2] == 0 && a[4] == 0 && a[6] == 0);

	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
N , M = map(int, input().split())

L=[[0]*2 for i in range(M)]

for i in range(M):
    L[i][0] , L[i][1] = map(int, input().split())

A=[0]*M
B=[0]*M

L=sorted(L ,key=lambda x: x[0])

for i in range(M):
    if L[i][0] == 1:
        A[i]=L[i][1]
    else:
        break
A=A[0:i]

L=sorted(L ,key=lambda x: -x[1])

for i in range(M):
    if L[i][1] == N:
        B[i]=L[i][0]
    else:
        break
B=B[0:i]

if((len(A)==0)or(len(B)==0)):
    print("IMPOSSIBLE")
    exit()
if((max(A)<min(B))or(max(B)<min(A))):
    print("IMPOSSIBLE")
    exit()

A.sort()
B.sort()
i=0
j=0
while((i<len(A))and(j<len(B))):
    if A[i] == B[j]:
        print("POSSIBLE")
        exit()
    elif A[i] > B[j]:j+=1
    else:i+=1
print("IMPOSSIBLE")


Measured memory_bytes: 48804
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

-- 
--
--

main = do
    a <- getI
    b <- getI
    h <- getI
    putStrLn . show $ ((a + b) * h) `div` 2


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    fastio;
  LL n;
  cin>>n;
  map<string,LL> m;
  while(n--){
   	string a;
    cin>>a;
    m[a]++;
  }
  cout<<"AC"<<" x "<<m["AC"]<<"\n";
  cout<<"WA"<<" x "<<m["WA"]<<"\n";
  cout<<"TLE"<<" x "<<m["TLE"]<<"\n";
  cout<<"RE"<<" x "<<m["RE"]<<"\n";
    
  	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(n>=b) n=b-1;
    long double ha=a*n*(long double)1.0/b;
    ll haa=floor(ha);
    cout<<haa<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;



int main(){
   int n;
   cin >> n;
   vector<int> L(n);
   REP(i,n) cin >> L[i];
   sort(ALL(L));
   int cnt = 0;
   for( int i = 0; i < n-2; ++i){
     for(int j = i+1; j < n-1; j++){
       int a = L[i];
       int b = L[j];
       auto x = lower_bound(L.begin()+j+1, L.end(), a+b);

       //auto x = lower_bound(ALL(L), a+b);
       //cout << x-L.begin() << endl;
       cnt += (int)(x-L.begin()) - (j+1);
       // cout << "iter:" << int(x-L.begin()) <<  endl;
       // cout << "cnt:" << cnt << endl;
     }
   }

   cout << cnt << endl;

  return 0;
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    LL N, D;
    LL ans = 0;
    cin >> N >> D;
    for(int i = 0;i < N;i++){
        LL X, Y;
        cin >> X >> Y;
        if(sqrt(X*X+Y*Y) <= D){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <string.h>

int main(void)
{
	int bunrui;
	int bangou[1000], tanpaku[1000], sisitu[1000], tansui[1000] ,cal[1000];
	int tanpaku_s, sisitu_s, tansui_s, cal_s;
	int flag;
	int i, j;
	
	while (1)
	{
		scanf("%d", &bunrui);
		
		if (bunrui == 0){
			break;
		}
		
		memset(bangou, 0, sizeof(bangou));
		memset(tanpaku, 0, sizeof(tanpaku));
		memset(sisitu, 0, sizeof(sisitu));
		memset(tansui, 0, sizeof(tansui));
		
		for (i = 0; i < bunrui; i++){
			scanf("%d%d%d%d", &bangou[i], &tanpaku[i], &sisitu[i], &tansui[i]);
			
			cal[i] = tanpaku[i] * 4 + tansui[i] * 4 + sisitu[i] * 9;
		}
		
		scanf("%d%d%d%d", &tanpaku_s, &sisitu_s, &tansui_s, &cal_s);
		
		flag = 0;
		
		for (i = 0; i < bunrui; i++){
			if (tanpaku[i] <= tanpaku_s && sisitu[i] <= sisitu_s && tansui[i] <= tansui_s && cal[i] <= cal_s){
				printf("%d\n", bangou[i]);
				flag = 1;
			}
		}
		
		if (flag == 0){
			printf("NA\n");
		}
		
	}
	
	return (0);
}

Measured memory_bytes: 0
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    nums = set(map(int, input().split()))
    if len(nums) == 2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5628
#include <iostream>
using namespace std;
const int MAX = 100005;

struct Node
{
	int p; //親のノード番号
	bool m; //Markされているか否か
};

Node A[MAX]; //memo:ノード番号は1~Nなので0は使わないことにする

void init()
{
	for (int i = 1; i < MAX; ++i)
	{
		A[i].m = false;
	}
	A[1].m = true;

	A[1].p = 1;
}

int query(int n)
{
	if (A[n].m)
	{
		return n;
	}
	else
	{
		query(A[n].p);
	}
}

void mark(int n)
{
	A[n].m = true;
}

int main()
{
	init();
	int N,Q,v;
	char s;
	while((cin >> N >> Q)&&(N > 0))
	{
		init();

		for (int i = 2; i <= N; ++i)
		{
			cin >> v;
			A[i].p = v;
		}

		long long ans = 0;

		for (int i = 0; i < Q; ++i)
		{
			cin >> s >> v;
			if (s == 'M')
			{
				mark(v);
			}
			else
			{
				ans += query(v);
			}
		}

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


Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>


using namespace std;

// 左側にRがいくつあるかを再帰的に探索する
void leftSideCheck(string _s,int _start, int *_num)
{
	if (_start - 1 < 0)
		return;

	if (_s[_start - 1] == 'R')
	{
		*_num += 1;
		leftSideCheck(_s, _start - 1, _num);
	}
	else
	{
		return;
	}
}
// 右側にLがいくつあるかを再帰的に探索する
void rightSideCheck(string _s, int _start, int *_num, int _max)
{
	if (_start + 1 >= _max)
		return;

	if (_s[_start + 1] == 'L')
	{
		*_num += 1;
		rightSideCheck(_s, _start + 1, _num, _max);
	}
	else
	{
		return;
	}
}

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

	int n = s.length();
	const int MAX_N = 100000;

	int answer[MAX_N] = {};

	// 左から見ていってRが連続する数を数える
	// 最後のRの位置にRLのペアがある
	int rCount = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
			rCount += 1;
		else
		{
			answer[i] += rCount / 2;
			answer[i - 1] += (rCount + 1) / 2;
			rCount = 0;
		}
	}

	// 右から見ていってLが連続する数を数える
	// 最後のLの位置にRLのペアがある
	int lCount = 0;
	for (int i = n-1; i >= 0; i--)
	{
		if (s[i] == 'L')
			lCount += 1;
		else
		{
			answer[i] += lCount / 2;
			answer[i + 1] += (lCount + 1) / 2;
			lCount = 0;
		}
	}




	for (int i = 0; i < n; i++)
		cout << answer[i] << " ";


	return 0;
}



Measured memory_bytes: 1024
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n = int(input())
h = list(map(int, input().split()))

dp = [1e9] * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i > 1):
         dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])


Measured memory_bytes: 23648
// ------------------------------------
// Date:2018/ 2/23
// Problem:ABC 045 ManyFormulas c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

int main()
{
  string S;
  int N;
  cin >> S;
  N = S.size();
  
  ll ans = 0ll;
  // 全探索はbitを立てるor立てないの2通りで2^(N-1)
  REP(i,(1<<N-1)) {
    ll sum = 0;
    REP(j,N) {
      sum = sum*10 + (S[j] - '0');
      if (i & (1<<j)) {
        ans += sum;
        // リセット
        sum = 0;
      }
    }
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    s = input()
    answer = [0] * len(s)
    nearest_R = 0
    nearest_L = 0

    for i in range(len(s)):
        if s[i] == "R":
            nearest_R = i
        else:
            if (i - nearest_R) % 2 == 0:
                answer[nearest_R] += 1
            else:
                answer[nearest_R + 1] += 1

        li = len(s) - i - 1
        if s[li] == "L":
            nearest_L = li
        else:
            if (nearest_L - li) % 2 == 0:
                answer[nearest_L] += 1
            else:
                answer[nearest_L - 1] += 1
    print(*answer, sep=" ")


main()


Measured memory_bytes: 79172
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int table[301][301];
int tate_ruisekiwa[301][301],yoko_ruisekiwa[301][301];


int main(){

	int N;

	scanf("%d",&N);

	for(int col = 0; col <= N; col++)tate_ruisekiwa[0][col] = 0;
	for(int row = 0; row <= N; row++)yoko_ruisekiwa[row][0] = 0;

	for(int row = 1; row <= N; row++){
		for(int col = 1; col <= N; col++){
			scanf("%d",&table[row][col]);
			tate_ruisekiwa[row][col] = table[row][col];
			yoko_ruisekiwa[row][col] = table[row][col];
		}
	}

	for(int col = 1; col <= N; col++){
		for(int row = 1; row <= N; row++)tate_ruisekiwa[row][col] += tate_ruisekiwa[row-1][col];
	}

	for(int row = 1; row <= N; row++){
		for(int col = 1; col <= N; col++)yoko_ruisekiwa[row][col] += yoko_ruisekiwa[row][col-1];
	}

	int ans = 0;

	for(int row = 1; row <= N; row++){
		for(int left = 1; left <= N; left++){
			for(int right = left; right <= N; right++){
				ans = max(ans,yoko_ruisekiwa[row][right]-yoko_ruisekiwa[row][left-1]);
			}
		}
	}

	for(int col = 1; col <= N; col++){
		for(int top = 1; top <= N; top++){
			for(int under = top; under <= N; under++){
				ans = max(ans,tate_ruisekiwa[under][col]-tate_ruisekiwa[top-1][col]);
			}
		}
	}

	int left_max,right;

	for(int row1 = 1; row1 <= N-1; row1++){
		for(int row2 = row1+1; row2 <= N; row2++){

			left_max = tate_ruisekiwa[row2][1]-tate_ruisekiwa[row1-1][1];

			for(int col = 2; col <= N; col++){
				right = tate_ruisekiwa[row2][col]-tate_ruisekiwa[row1-1][col];
				ans = max(ans,left_max+right);
				left_max = max(left_max+table[row1][col]+table[row2][col],right);
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}

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

int main(void){
  double d;
  while(cin >> d){
    if(abs(d) < 0.000000001) break;
    int den = -1, num = -1;
    for(int i = 1;;i++){
      double tmp = 20.0;
      for(int j = i*3;;j++){
        double frac = (double)j / (double)i;
        if(M_PI-d < frac && frac < M_PI+d){
          if( abs(M_PI - frac) < abs(M_PI - tmp) ){
            den = i; num = j;
            tmp = frac;
          }
        }
        if(M_PI+d < frac) break;
      }
      if(den != -1) break;
    }
    cout << num << "/" << den << endl;
  }
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct A {
    bool operator<(const A &a) const {
        return s != a.s ? s < a.s : p > a.p;
    }
    string s;
    int p, i;
};

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

    vector<A> a(n);
    for (int i = 0; i < n; i++) {
        string s;
        int p;
        cin >> s >> p;
        a[i] = { s, p, i };
    }
    sort(a.begin(), a.end());

    for (int i = 0; i < n; i++) {
        cout << a[i].i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; int Q; cin >> S >> Q;

    string L = "", R = "";
    int state = 0;
    REP(i, 0, Q) {
        int q; cin >> q;
        if (q == 1) {
            state = (state + 1) % 2;
            continue;
        }
        int f; char c; cin >> f >> c;
        if (f == 1) {
            if (state == 0) {
                L = c + L;
            } else {
                R = R + c;
                // R = c + R;
            }
        } else {
            if (state == 0) {
                R = R + c;
            } else {
                L = c + L;
                // L = L + c;
            }
        }
    }

    if (state == 0) {
        cout << L << S << R << endl;
    } else {
        reverse(ALL(R));
        reverse(ALL(S));
        reverse(ALL(L));
        cout << R << S << L << endl;
    }

    return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
char s[200005];
deque<char>q;
deque<char>::iterator it;
int main(){
	int st=0;//头
	cin>>s+1;
	int qq;
	int n=strlen(s+1);
	for(int i=1;i<=n;++i){
		q.push_back(s[i]);
	}
	cin>>qq;
	int t,f;
	char c;
	while(qq--){
		cin>>t;
		if(t==1)st^=1;
		if(t==2){
			cin>>f;
			if(f==1){
				cin>>c;
				if(st==0)q.push_front(c);
				else q.push_back(c);
			}
			else{
				cin>>c;
				if(st==0)q.push_back(c);
				else q.push_front(c);
			}
		}
	}
	if(st==0){
		it=q.begin();
		while(!q.empty()){
			cout<<q.front();
			q.pop_front();
		}
	}
	else{
		while(!q.empty()){
			cout<<q.back();
			q.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<set>
using namespace std;
int f[10],n,k;
string v[10];
set<string>u;
void F(int d,string s)
{
	if(d==k)u.insert(s);
	else for(int i=0;i<n;++i)
		if(!f[i])
		{
			f[i]=1;
			F(d+1,s+v[i]);
			f[i]=0;
		}
}
int main()
{
	int i;
	string s;
	while(cin>>n>>k,n)
	{
		for(i=0;i<n;++i)cin>>s,v[i]=s;
		u.clear();
		F(0,"");
		cout<<u.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    char c[20];
    scanf("%s", c);

    for (int i = 0; i < strlen(c); i++) {
        
        if(c[i]==','){
            printf("%c",' ');
        }else{
            printf("%c",c[i]);
        }
    }



    return 0;

}


Measured memory_bytes: 128
while 1:
  n=input()+1
  if n==1: break
  x=[]
  y=[0]*n
  N=range(n)
  for i in N[:-1]:
    a=map(int,raw_input().split(' '))
    a.append(sum(a))
    x.append(a)
    for j in N: y[j]+=a[j]
  x.append(y)
  for i in N: print "".join([str(e).rjust(5) for e in x[i]])

Measured memory_bytes: 4224
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

x1, y1, x2, y2 = MAP()

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx

x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4) 



Measured memory_bytes: 5144
#include <stdio.h>
#define MOD 1000000007

int N, A[112345];
int count[112345];
long long int ans = 1;

int main(void)
{
    scanf("%d", &N);
    for (int i = 0; i < N; ++i)
    {
        scanf("%d", &A[i]);
    }

    for (int i = 0; i < N; ++i)
    {
        ++count[A[i]];
    }
    for (int i = 0; i < N; ++i)
    {
        if (N % 2 == 0)
        {
            if (count[i] % 2 == 1)
            {
                ans = 0;
                break;
            }
        }
        else
        {
            if (i == 0)
            {
                if (count[0] > 1)
                {
                    ans = 0;
                    break;
                }
            }
            else if (count[i] % 2 == 1)
            {
                ans = 0;
                break;
            }
        }
    }
    if (ans == 1)
    {
        for (int i = 0; i < N / 2; ++i)
        {
            ans *= 2;
            ans %= MOD;
        }
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const int MAX_N=100,M=5050;
const ll MOD=1e9+7;
int N;
ll K,dp[MAX_N][M+1];
void add(ll &a,ll b){
	a+=b;
	if(a>=MOD){
		a-=MOD;
	}
}
void sub(ll &a,ll b){
	a-=b;
	if(a<0){
		a+=MOD;
	}
}
int main(){
	scanf("%d %lld",&N,&K);
	dp[N-1][0]=K;
	if(K==N){
		dp[N-1][1]=1;
	}else{
		dp[N-1][0]++;
	}
	for(int i=N-1;i>0;i--){
		REP(j,M+1){
			REP(k,K+1){
				int j2=j;
				if(k<=i){
					int j0=j;
					if(j0>=i-k){
						j0-=i-k;
						j2++;
						j2+=j0/i;
					}
				}
				add(dp[i-1][j2],dp[i][j]);
			}
		}
	}
	ll ans=1;
	REP(i,N-1){
		ans*=K+1;
		ans%=MOD;
	}
	ans*=N;
	ans%=MOD;
	ans*=K*(K+1)/2;
	ans%=MOD;
	REP(i,M+1){
		sub(ans,dp[0][i]*i%MOD);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4096
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;

long long sankaku(long long n);

int main(void){
        long long i,j;
        long long n;
        scanf("%lld",&n);
        
        long long ans;
        ans=0;
        for(i=1;i<=n;i++){
                ans += i * sankaku(n/i);
        }
        printf("%lld\n",ans);
        return 0;
}

long long sankaku(long long n){
        return (n*(n+1)/2);
}


Measured memory_bytes: 3824