akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// age ye mosh dp ro baze dashti dp tedad baz shodeye baste nashode yadet nare !!
/// joooob zadam
const int N=202+100;
char c[N][N],a[N][N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            cin >> c[i][j];
        }
    }
    ll ans=0;
    for (int k=0;k<n;k++){
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                ll x=(i+k)%n;
                ll y=j;
                a[i][j]=c[x][y];
            }
        }
        ll p1=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if (a[i][j]!=a[j][i]){
                    p1=1;
                }
            }
        }
        if (!p1){
            //cout << k << endl;
            ans+=n;
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll k,i;
  cin >> k;
  if(k==7 || k==1){
    cout << 1 << endl;
    return 0;
  }
  ll res=7;
  for(i=1;i<=10000000;i++){
    if(res%k==0){
      cout << i << endl;
      return 0;
    }
    res=res*10+7;
    res=res%k;
  }
  cout << -1  << endl;
}

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

using namespace std;

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    for (auto && tx : t) cin >> tx;
    vector<ll> a(n);
    for (auto && ax : a) cin >> ax;


    ll ans = 1;
    if (t[n - 1] != a[0]) {
        ans *= 0;
    }
    const ll MOD = 1000000007;
    for (int i = 1; i < n - 1; ++i) {
        if (t[i - 1] != t[i] && a[i] != a[i + 1]) {
            if (t[i] != a[i]) {
                ans *= 0;
                continue;
            } else {
                continue;
            }
        } else if (t[i - 1] != t[i]) {
            if (t[i] > a[i]) {
                ans *= 0;
                continue;
            } else {
                continue;
            }
        } else if (a[i] != a[i + 1]) {
            if (a[i] > t[i]) {
                ans *= 0;
                continue;
            } else {
                continue;
            }
        } else {
            // cout << "i:" << i << " min = " <<  min(a[i], t[i]) << endl;
            ans *= min(a[i], t[i]);
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    double x1,x2,y1,y2,d;
    cin>>x1>>y1>>x2>>y2;
    d=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
    printf("%lf",d);

    return 0;
}


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

int main(void){
  int b,r,g,c,s,t;
  while(cin>>b>>r>>g>>c>>s>>t,b+r+g+c+s+t){
    int bg = b*5 + r*3;
    t -= bg + s;
    int m = 100 - t * 3 + bg * 13 + b * 15 + r * 15 + g * 7 + c * 2;
    cout<<m<<endl;
  }
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char c; cin >>c;
	if (c>='a' && c<='z') cout <<"a";
	else cout <<"A";
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3588
import fractions
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
ans = abs(x[0]-X)
if len(x) != 1:
    for i in range(N):
        ans1 = abs(X-x[i])
        ans = fractions.gcd(ans,ans1) 
print(ans)

Measured memory_bytes: 88300
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func asInt(s string) []int {
	arr := strings.Split(s, " ")
	is := make([]int, 0, len(arr))
	for _, str := range arr {
		i, _ := strconv.Atoi(str)
		is = append(is, i)
	}
	return is
}

func main() {
	ab := asInt(nextLine())
	a := ab[0]
	if a >= 13 {
		fmt.Println(ab[1])
	} else if a <= 5 {
		fmt.Println("0")
	} else {
		fmt.Println(ab[1] / 2)
	}
}


Measured memory_bytes: 640
def main():
    mod=1000000007
    inv=lambda x: pow(x,mod-2,mod)
    k=int(input())
    s=input().strip()
    l=len(s)
    
    n=k+l
    Fact=[1] #階乗
    for i in range(1,n+1):
        Fact.append(Fact[i-1]*i%mod)
    Finv=[0]*(n+1) #階乗の逆元
    Finv[-1]=inv(Fact[-1])
    for i in range(n-1,-1,-1):
        Finv[i]=Finv[i+1]*(i+1)%mod
    def comb(n,r):
        if n<r:
            return 0
        return Fact[n]*Finv[r]*Finv[n-r]%mod

    ans=0
    p=1
    for i in range(l,l+k+1)[::-1]:
        ans+=comb(l+k,i)*p
        ans%=mod
        p*=25
        p%=mod
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 211352
#include <iostream>

using namespace std;

int main(){
 int x, y;
 while(1){
 cin >> x >> y;
 if(x == 0 && y == 0){
  break;
 }
 if(x > y){
  cout << y << " " << x << endl;
 }else{
  cout << x << " " << y << endl;
 }
 
 }
 return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n;cin>>n;
  double a[n+10];
  double sum=0;ll mul=1;
  rep(i,0,n){
    cin>>a[i];
    sum+=1/a[i];
  }

  cout<<setprecision(15)<<1/sum<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int C = sc.nextInt();
    int counter = 0;
   	int B[] = new int[M];
    
    for(int i=0; i<M; i++) {
      B[i] = sc.nextInt();
    }
    
    for(int j=0; j<N; j++) {
      int total = C;
      for(int k=0; k<M; k++) {
        total += sc.nextInt() * B[k];
      }
      if(total > 0) {
        counter++;
      }
    }
    System.out.println(counter);
  }
}


Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b;
  cin >> a >> b;
  char arr[a][b];
  for(int i=0;i<a;i++)
  {
    for(int j=0;j<b;j++)
    {
      cin >> arr[i][j];
    }
  }
  for(int i=0;i<b+2;i++)
  {
    cout << "#";
  }
  cout << endl;
  for(int i=0;i<a;i++)
  {
    for(int j=0;j<b+2;j++)
    {
      if(j==0 || j==b+1)
        cout << "#";
      else
        cout << arr[i][j-1];
    }
    cout << endl;
  }
  for(int i=0;i<b+2;i++)
  {
    cout << "#";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

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

  int c[10][10];
  rep(i, 10)rep(j, 10){
    c[i][j] = 0;
  }
  repi(i, 1, n + 1)
  {
    string s = to_string(i);
    int first, last;
    first = s[0] - '0';
    last = s[s.length() - 1] - '0';
    c[first][last]++;
  }

  int ans = 0;
  rep(i, 10)
  {
    rep(j, 10)
    {
      ans += c[i][j] * c[j][i];
    }
  }

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

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




int main() {
  ll n,q;
  cin >> n >> q;
  vector<tuple<ll,ll,ll>> a(n);
  rep(i,n){
    ll s1,t1,x1;
    cin>>s1>>t1>>x1;
    a[i]=make_tuple(x1,s1-x1,t1-x1);
  }
  sort(a.begin(),a.end());
  vector<ll>ans(q,-1);
  set<P> Q;
  rep(i,q){
    ll d1;
    cin>>d1;
    Q.insert(make_pair(d1,i));
  }
rep(i,n){
  ll s1,t1,x1;
  tie(x1,s1,t1)=a[i];
  auto it=Q.lower_bound(make_pair(s1,ll(-1)));
  while(it!=Q.end()){
    if((it->first)>=t1)break;
    ans[it->second]=x1;
  //  cout<<it->second<<" "
  //  if()
    Q.erase(it++);
  }
}
rep(i,q){
  cout<<ans[i]<<endl;
}


}


Measured memory_bytes: 21988
n, k = map(int, input().split())
h = list(map(int, input().split()))
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, min(k+1, i+1)):
        dp[i] = chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])

Measured memory_bytes: 55392
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]

# 各マスから左に何マスいったら壁にぶつかるか
left = [[-1 for _ in range(W)] for _ in range(H)]
right = [[-1 for _ in range(W)] for _ in range(H)]
top = [[-1 for _ in range(W)] for _ in range(H)]
bottom = [[-1 for _ in range(W)] for _ in range(H)]


# 左に何マスいったらぶつかるか
for i in range(H):
    count = 0
    for j in range(W):
        if Ss[i][j] == "#":
            count = 0
        else:
            left[i][j] = count
            count += 1

# 右に何マスいったらぶつかるか
for i in range(H):
    count = 0
    for j in range(W):
        k = W-j-1
        if Ss[i][k] == "#":
            count = 0
        else:
            right[i][k] = count
            count += 1

# 上に何マスいったらぶつかるか
for j in range(W):
    count = 0
    for i in range(H):
        if Ss[i][j] == "#":
            count = 0
        else:
            top[i][j] = count
            count += 1

# 下に何マスいったらぶつかるか
for j in range(W):
    count = 0
    for i in range(H):
        k = H - i - 1
        if Ss[k][j] == "#":
            count = 0
        else:
            bottom[k][j] = count
            count += 1

# print("right")
# for i in range(H):
#     print(right[i])
#
# print("left")
# for i in range(H):
#     print(left[i])
#
# print("bottom")
# for i in range(H):
#     print(bottom[i])
#
# print("top")
# for i in range(H):
#     print(top[i])

max_score = 0
for i in range(H):
    for j in range(W):
        if Ss[i][j] != "#":
            score = left[i][j] + right[i][j] + top[i][j] + bottom[i][j] + 1
            max_score = max(max_score, score)

print(max_score)


Measured memory_bytes: 184068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ans += min(b[i], a[i] + a[i+1]);
        if (b[i] > a[i]) a[i+1] = max(a[i+1] - (b[i] - a[i]), 0);
    }
    cout << ans << endl;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,l,ans;
vector<int> v;

main() {
    cin >> n;
    rep(i,n*2) cin >> l,v.pb(l)
    sort(rall(v));
    rep(i,n) ans+=v[i*2+1];
    ct(ans)
}


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

void insert(int _value);
void delete(int _value);
void deleteFirst(void);
void deleteLast(void);

struct Node{

  struct Node* next;
  struct Node* prev;
  int value;

};

struct Node* head;
struct Node* tail;
main(){

  int i;
  int n;
  int tmpValue;
  char str[20];
  struct Node* node;

  head = (struct Node*)malloc(sizeof(struct Node));
  tail = (struct Node*)malloc(sizeof(struct Node));
  head->next = tail;
  head->prev = NULL;
  tail->next=NULL;
  tail->prev=head;
  head->value = 0;
  tail->value=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",str);
    if(!strcmp(str,"insert")){
      scanf("%d",&tmpValue);
      insert(tmpValue);
    }else if(!strcmp(str,"deleteFirst")){
      deleteFirst();
    }else if(!strcmp(str,"deleteLast")){
      deleteLast();
    }else if(!strcmp(str,"delete")){
      scanf("%d",&tmpValue);
      delete(tmpValue);
    }
  }

  for(node=head->next; node != tail; node=node->next){
    printf("%d",node->value);
    if(node->next!=tail){
      printf(" ");
    }
  }
  printf("\n");

  return 0;

}

void insert(int _value){

  struct Node* newNode;
  struct Node* tmpNode;

  newNode = (struct Node*)malloc(sizeof(struct Node));

  tmpNode = head->next;
  if(tmpNode != NULL){
    tmpNode->prev = newNode;
  }
  head->next = newNode;
  newNode->next = tmpNode;
  newNode->prev = head;

  newNode->value = _value;

}

void delete(int _value){

  struct Node* node;
  struct Node* tmpNode;
  for(node=head->next; node != NULL; node=node->next){
    if(node->value == _value){
      tmpNode = node->prev;
      if(tmpNode != NULL){
	tmpNode->next = node->next;
      }
      if(node->next != NULL){
	node->next->prev = tmpNode;
      }
free(node);
      break;
    }
  }

}

void deleteFirst(){

  struct Node* node;
  node=head->next;

  if(head != NULL){
    head->next= node->next;
  }
  if(node->next != NULL){
    node->next->prev = head;
  }
  //free(node);

}

void deleteLast(){

  struct Node* tmpNode;

  tmpNode=tail->prev;
  tail->prev=tmpNode->prev;
  tmpNode->prev->next=tail;

  //free(tmpNode);

}

Measured memory_bytes: 17000
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    S = input()
    T = input()
    ans = 0
    if S == T:
        print(0)
        sys.exit()
    for i in range(len(S)-1):
        if S[i] != T[i]:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11476
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}

int main() {
	while (1) {
		long long int N; cin >> N;
		if (!N)break;
		auto v(divisor(N));
		long long int sum = accumulate(v.begin(), v.end(), 0ll);
		if (sum > 2 * N)cout << "abundant number" << endl;
		else if (sum == 2 * N)cout << "perfect number" << endl;
		else cout << "deficient number" << endl;

	}
	return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>

int main(){
	int x=0,i,n,data[100];
	while(scanf("%d",&x)!=EOF){
		if(x==0){
			printf("%d\n",data[i]);
			i--;
		}else{
			i++;
			data[i]=x;
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int sum = 0;
  int h,n;
  cin >> h >> n;;
  
  vector<int> as(n+10);

  for(int i= 0; i<n ; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum < h) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll a,b,c;cin >>a>>b>>c;
   int k;cin >>k;
   ll cnt=0;
   while(b<=a){
       b*=2;cnt++;
   }
//    cout <<cnt<<endl;
    while(c<=b){
        c*=2;cnt++;
    }
//    cout <<cnt<<endl;
//    cout <<a<<" "<<b<<" "<<c<<endl;
    if(cnt<=k)puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3592
#44b
w = input()
w = sorted(w)
ans = True

if len(w)% 2!=0:
    ans = False

else:
    for i in range (len(w)//2):
        if w[2*i] == w[2*i+1]:
            ans = True
        else:
            ans = False
            break
print('Yes' if ans == True else 'No')
            

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



ll n, k, num[2020], res;
vector<ll> d;

signed main() {
	cin >> n >> k;
	for (int i=1; i*i<=n; i++) if (n%i==0) {
		d.push_back(i);
		if (i*i!=n) d.push_back(n/i);
	}
	sort(all(d));
	rep(i,d.size()) {
		num[i] = mop(k,(d[i]+1)/2);
		rep(j,i) if (d[i]%d[j]==0) (num[i] += mod - num[j]) %= mod;
		(res += num[i] * d[i] / (d[i]%2 ? 1 : 2)) %= mod;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m, aux, tot; 
	cin >> m >> n;

	if(n==1){
		tot=0;
	}else if(m>=n){
		tot = 1;
	}else{
		tot=1;
		for(int i=1;i<n; i++){
			aux = (m-1)*i + m;
			tot++;
			if(aux>=n){
				break;
			}
			
		}
	}

	cout << tot<< endl;
	return 0;
}

Measured memory_bytes: 3616
import math

N = int(input())
x1 = int(math.ceil(N/1.08))
x2 = int(math.floor(N/1.08))

price1 = int(x1*1.08)
price2 = int(x2*1.08)

if price1 == N:
    print(x1)
elif price2 == N:
    print(x2)
else:
    print(':(')

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, d;
	cin >> n >>d;
	
	d = 2*d+1;
	
	cout <<  (n+d-1) /d <<"\n";
	return 0;
}


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

int main(){
  ll x;
  cin >> x;
  ll x1=x%11,x2=x/11,ans=0;
  ans=x2*2;
  if(x1==0){
    
  }else if(x1<7){
    ans++;
  }else{
    ans++;
    ans++;
  }
  cout << ans << endl;;
 }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int INF = 1 << 28;
int dist[20][100][100];
int d[100][100];
int p[20], q[20][50], r[20][50];
int main() {
	int n, m, c, s, g;
	while (cin >> n >> m >> c >> s >> g, n) {
		s--; g--;
		fill((int*)dist, (int*)(dist + 20), INF);
		for (int i = 0; i < c; i++) for (int j = 0; j < n; j++) dist[i][j][j] = 0;
		for (int i = 0; i < m; i++) {
			int x, y, d, num;
			cin >> x >> y >> d >> num;
			x--; y--;
			num--;
			dist[num][x][y] = dist[num][y][x] = min(dist[num][x][y], d);
		}
		for (int i = 0; i < c; i++) {
			scanf("%d", &p[i]);
		}
		for (int i = 0; i < c; i++) {
			for (int j = 0; j + 1 < p[i]; j++) {
				scanf("%d", &q[i][j]);
			}
			for (int j = 0; j< p[i]; j++) {
				scanf("%d", &r[i][j]);
			}
		}
		for (int com = 0; com < c; com++) {
			for (int k = 0; k < n; k++) {
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						dist[com][i][j] = min(dist[com][i][j], dist[com][i][k] + dist[com][k][j]);
					}
				}
			}
		}
		fill((int*)d, (int*)(d + n), INF);
		for (int i = 0; i < n; i++) d[i][i] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int tmp = INF;
				for (int com = 0; com < c; com++) {
					int cost = 0;
					if (dist[com][i][j] == INF) continue;
					if (p[com] == 1) {
						cost = dist[com][i][j] * r[com][0];
						tmp = min(tmp, cost);
						continue;
					}
					int prev = 0;
					for (int k = 0; k + 1 < p[com]; k++) {
						cost += (min(q[com][k], dist[com][i][j]) - prev)*r[com][k];
						prev = q[com][k];
						if (q[com][k] > dist[com][i][j]) break;
					}
					cost += max(dist[com][i][j] - q[com][p[com] - 2], 0)*r[com][p[com] - 1];
					tmp = min(tmp, cost);
				}
				d[i][j] = tmp;
			}
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		if (d[s][g] == INF) cout << -1 << endl;
		else cout << d[s][g] << endl;
	}
}

Measured memory_bytes: 3984
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 200005
using namespace std;

typedef long long ll;
ll n, ans, a[N], s[N], b[4];
ll f(ll p, ll q){
	return s[q] - s[p - 1];
}

ll ab(ll p) {return p > 0 ? p : -p;}
int main()
{
	ll i, j, k;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%lld", &a[i]);
		s[i] = s[i - 1] + a[i];
	}
	j =1;
	k = 3;
    for (i = 2; i <= n - 2; i++) {
		for (; j < i - 1; j++) {
//			if (max(f(1, j), f(j + 1, i)) < max(f(1, j + 1), f(j + 2, i))) break;
			if (ab(f(1, j) - f(j + 1, i)) < ab(f(1, j + 1) - f(j + 2, i))) break;
		}
		for (; k < n - 1; k++) {
//			if (max(f(1, j), f(j + 1, i)) < max(f(1, j + 1), f(j + 2, i))) break;
			if (ab(f(i + 1, k) - f(k + 1, n)) < ab(f(i + 1, k + 1) - f(k + 2, n))) break;
		}
		b[0] = f(1, j);
		b[1] = f(j + 1, i);
		b[2] = f(i + 1, k);
		b[3] = f(k + 1, n);
		sort(b, b + 4);
		if (i == 2 || b[3] - b[0] < ans) ans = b[3] - b[0];
    }
    cout << ans;
    return 0;
}


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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int n = max({a,b,c});
    int sum = 3*n-a-b-c;
    int ans = 0;
    if(sum%2){
        ans = (sum+3)/2;
    }else{
        ans = sum/2;
    }
    cout<< ans<<endl;
}



Measured memory_bytes: 256
import sys
A,B = map(int,input().split())
S = input()
array_S = list(S)

if not (1 <= A <= 5 and 1 <= B <= 5):
    sys.exit()

if len(S) != (A + B + 1):
    sys.exit()

for I in range(len(array_S)):
    if I == A:
        continue
    if not array_S[I].isdecimal():
        print('No')
        sys.exit()

if array_S[A] == '-' and len(S) == (A + B + 1):
    print('Yes')
else:
    print('No')

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


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

  if(n % (2*d + 1) == 0){
    cout << n / (2*d+1) << endl;
  }else{
    cout << n / (2*d+1) + 1 << endl;
  }

  
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d", &a, &b);
  if(a<b){
    printf("a < b\n");
  } else if(a>b){
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }
  return 0;
}


Measured memory_bytes: 2064
// ------- PBDS ------ //
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ------- PBDS ------ //

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define pi 3.1415926535
#define endl "\n"
#define vll vector<ll>
#define MULTI int T; cin >> T; while(T--)
#define all(a)      (a).begin(),(a).end()
#define here cout<<"I'm here\n";
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele<<" "; cout<<endl;
}
vector<ll> adj[200001];
bool vis[200001];

// ------- PBDS ------ //
typedef tree<
// change this for any data-type
string,
null_type,
// change this for any data-type
less<string>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

/*
    to get the position of an element in set , do
    s.order_of_key(ele);
    this returns the number of elements strictly lesser than ele in set s
    Let us assume we have a set s : {1, 5, 6, 17, 88}, then :
    s.order_of_key(6) : Count of elements strictly smaller than 6 is 2.
    s.order_of_key(25) : Count of elements strictly smaller than 25 is 4.

    to get the element at position k
    s.find_by_order(k);
    returns an iterator to the ele counting from 0
    Let us assume we have a set s : {1, 5, 6, 17, 88}, then :
    *(s.find_by_order(2)) : 3rd element in the set i.e. 6
    *(s.find_by_order(4)) : 5th element in the set i.e. 88
*/

// ------- PBDS ------ //

clock_t time_p=clock();
void purvansh11()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

//BINARY EXPONENTIATION  -- O(log2(b))
ll power(ll a, ll b) {
    /*
        for 3^11 :
        as 11 -> 1011, we mean 3^8 * 3^2 * 3^1
        so multiply for all ones in binary rep of b
    */

    ll ans = 1;
    ll num = a;
    while (b > 0) {
        if (b & 1) ans = ((ans % MOD) * (num % MOD)) % MOD;
        num = ((num % MOD) * (num % MOD)) % MOD;
        b /= 2;
    }
    return ans;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    SPEED;
    cout.precision(8);
    cout << fixed;
    ll dp[5000];
    ll n;
    cin>>n;
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    dp[1]=0; dp[2]=0; dp[3]=1;
    for(ll i=4;i<=n;i++){
        dp[i]=1;
        for(ll j=3;j<=i-3;j++){
            dp[i]=(dp[i]%MOD + dp[j]%MOD)%MOD;
        }
    }
    // for(int i=0;i<=n;i++) cout<<dp[i]<<" ";
    cout<<dp[n];   
    purvansh11();
    return 0;
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long k,t,n,m,p;
    cin>>n>>m;
    if(n<m)
    {
        cout<<min(n,m-n)<<endl;
    }
    else
    {
        n=n%m;
        cout<<min(n,m-n)<<endl;
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;

  bool flg = true;
  long double X;
  int a, b;
  for (long i=0; i<400000000; i++) {
    X = i;
    a = X * 0.08;
    b = X * 0.1;
    if (a == A && b == B) {
      cout << i;
      flg = false;
      break;
    }
  }
  if (flg) cout << "-1";
    
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define rev(v) (v).rbegin(), (v).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> P;
typedef long long ll;


int check(int state, vector<vi> a, const vector<vi> &b){
	rep(i, a.size()){
		if((state>>i)&1){
			a[i] = b[i];
		}
	}
	int sum = 0;
	rep(j, a[0].size()){
		int cnt0 = 0, cnt1 = 0;
		rep(i, a.size()){
			if(a[i][j])cnt1++;
			else cnt0++;
		}
		sum += max(cnt0, cnt1);
	}

	return sum;
}

int main(){
	//freopen("test.txt", "r", stdin);
	int R, C;
	while(cin >> R >> C, R|C){
		vector<vi> a(R, vi(C, 0)), b(R, vi(C, 0));
		rep(i, R) rep(j, C){
			cin >> a[i][j];
			b[i][j] = !a[i][j];
		}

		int ans = 0;
		int state = 0;
		while((state>>R) != 1){
			ans = max(ans, check(state, a, b));
			state++;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2388
N = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
                    cnt += 1

print(cnt)

Measured memory_bytes: 9204
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

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

    int n;
    cin >> n;
    int m = n - 1;
    Graph G(n);
    vector<pair<int, int>> ab(m);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        G[a].push_back(b);
        G[b].push_back(a);

        ab[i] = {a, b};
    }

    int k = 0;
    for (int i = 0; i < n; i++) {
        k = max(k, (int)G[i].size());
    }

    map<pair<int, int>, int> ans;
    queue<pair<int, int>> que;
    que.push({0, -1});
    while (!que.empty()) {
        int v = que.front().first;
        int p = que.front().second;
        que.pop();

        int cur = 1;
        for (auto nv : G[v]) {
            if (nv == p) {
                continue;
            }
            if (ans[{p, v}] == cur) {
                cur++;
            }

            que.push({nv, v});
            ans[{v, nv}] = cur;
            cur++;
        }
    }

    cout << k << endl;
    for (int i = 0; i < m; i++) {
        cout << ans[ab[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 15752
import functools

def find_all_rings(items):
    "items: (??°???, ?????????????????????????????????)"
    l = len(items)
    check_list = [False] * l
    rings = []
    i = 0
    while i < l:
        if check_list[i] == False:
            ring = []
            first = items[i]
            ring.append(first)
            check_list[i] = True
            item_index = first[1]
            item = items[item_index]
            while item[0] != first[0]:
                ring.append(item)
                check_list[item_index] = True
                item_index = item[1]
                item = items[item_index]
            rings.append(ring)
        i += 1
    return rings

def compute_ring_cost(min_all, ring):
    l = len(ring)
    if l <= 1:
        return 0
    w = [item[0] for item in ring]
    min_ring = min(w)
    sum_ring = sum(w)
    if (l + 1) * min_all < (l - 3) * min_ring:
        return sum_ring + min_ring + (l + 1) * min_all
    else:
        return sum_ring + (l - 2) * min_ring

n = int(input())
ns = list(map(int, input().split()))
items = []
sorted_items = []
for i in range(n):
    item = (ns[i], i)
    items.append(item)
    sorted_items.append(item)

sorted_items.sort(key = lambda x : x[0])

for i in range(n):
    item = sorted_items[i]
    items_index = item[1]
    items[items_index] = (item[0], i)

rings = find_all_rings(items)
compute_ring_cost1 = functools.partial(compute_ring_cost, min(ns))
print(sum(map(compute_ring_cost1, rings)))

Measured memory_bytes: 8552
s = input()

w1 = [ "R", "U", "D"]
w2 = [ "L", "U", "D"]

for i in range(len(s)):
  if i % 2 == 0:
    if not s[i] in w1 :
      print("No")
      exit()
  else :
    if not s[i] in w2 :
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  int pre;
  cin >> pre;
  for(int i = 0; i < n-1; i++){
    int a;
    cin >> a;
    if(pre == a){
      ans++;
      pre = -1;
    }
    else pre = a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N;
int A[202020];
ll S[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		S[i+1]=S[i]+A[i];
	}
	
	ll mi=1LL<<60;
	for(i=1;i<N;i++) {
		ll a=S[i];
		ll b=S[N]-a;
		mi=min(mi,abs(a-b));
	}
	cout<<mi<<endl;
	
	
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using ll = long long;
using namespace std;
int main() {
  	ll n, l, mn, minabs = 1000;
  	vector<ll> v;
    cin >> n >> l;
  	REP(i, n){
      	v.push_back(l+i);
      	if (abs(l+i) <= minabs) {
          	minabs = abs(l+i);
          	mn = l+i;
        }
    }
  
  	cout << accumulate(v.begin(), v.end(), 0) - mn << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "No"; return;}

void solve() {
    string s; cin >> s;
    loop(i, s.size())
        if ((!(i & 1) && s[i] == 'L') || ((i & 1) && s[i] == 'R'))
            no;
    cout << "Yes";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n,l;
	cin>>n>>l;
	string s[100];
	for(int i=0;i<n;i++)cin>>s[i];
	sort(s,s+n);
	for(int i=0;i<n;i++)cout<<s[i];
	cout<<endl;
	return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<bool>mp(1e6,true); mp.front()=mp.at(1)=false;
	for(int i=2;i*i<1e6;++i){
		if(!mp.at(i))continue;
		for(int j=i*i;j<1e6;j+=i){
			mp.at(j)=false;
		}
	}
	vector<int>sum(1e6); sum.front()=0;
	for(int i=1;i<1e6;++i){
		sum.at(i)=sum.at(i-1)+mp.at(i);
	}
	int n;
	while(cin>>n){
		cout<<sum.at(n)<<"\n"s;
	}
}


Measured memory_bytes: 6632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Deven-Eleven
public class Main{

	static int[][] move = {{0,-1},{1,-1},{-1,0},{1,0},{0,1},{1,1}};
	static int[][] move2 = {{-1,-1},{0,-1},{-1,0},{1,0},{-1,1},{0,1}};
	static int m, n, s;
	
	static int[][] bfs(int x, int y){
		int[][] r = new int[m+1][n+1];
		boolean[][] v = new boolean[m+1][n+1];
		int step = 1;
		List<int[]> l = new ArrayList<int[]>();
		v[x][y] = true;
		l.add(new int[]{x, y});
		while(!l.isEmpty()){
			List<int[]> next = new ArrayList<int[]>();
			for(int[]a:l){
				for(int k=0;k<6;k++){
					int nx = a[0]+(a[1]%2==0?move[k][0]:move2[k][0]);
					int ny = a[1]+(a[1]%2==0?move[k][1]:move2[k][1]);
					if(1<=nx&&nx<=m&&1<=ny&&ny<=n&&!v[nx][ny]){
						v[nx][ny] = true;
						r[nx][ny] = step;
						next.add(new int[]{nx, ny});
					}
				}
			}
			step++;
			l = next;
		}
		return r;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			if(m==0)break;
			n = sc.nextInt();
			s = sc.nextInt();
			int[][][] a = new int[s][m+1][n+1];
			for(int i=0;i<s;i++)a[i]=bfs(sc.nextInt(), sc.nextInt());
			int max = 0;
			int t = sc.nextInt();
			while(t--!=0){
				int[][] r = bfs(sc.nextInt(), sc.nextInt());
				int c = 0;
				for(int x=1;x<=m;x++){
					for(int y=1;y<=n;y++){
						boolean f = true;
						for(int k=0;k<s;k++){
							if(r[x][y]>=a[k][x][y])f=false;
						}
						if(f)c++;
					}
				}
				max = Math.max(max, c);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
void chmax(int& a, int b) {
  if (a < b) a = b;
}

void chmin(int& a, int b) {
  if (a > b) a = b;
}
  
int main () {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    chmax(X, x);
  }
  for (int i = 0; i < M; i++) {
    int y;
    cin >> y;
    chmin(Y, y);
  }
  
  if (X < Y) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    readln.split.to!(int[]).reduce!"a ^ b".writeln;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

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

    int n, ans = 0;
    cin >> n;
    vector<int> l(n), r(n);
    rep(i, 0, n) {
        cin >> l[i] >> r[i];
    }
    int max_l = *max_element(l.begin(), l.end());
    int min_r = *min_element(r.begin(), r.end());

    vector<pair<int, int>> p(n);
    rep(i, 0, n) {
        p[i] = make_pair(max(0, min_r - l[i] + 1), -max(0, r[i] - max_l + 1));
    }
    sort(p.begin(), p.end());
    int mx = 1.1e9;
    rep(i, 0, n) {
        int c = r[i] - l[i] + 1;
        c += max(0, min_r - max_l + 1);
        ans = max(ans, c);
    }
    rep(i, 0, n - 1) {
        mx = min(mx, -p[i].second);
        ans = max(ans, mx + p[i + 1].first);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++)
    cin >> b[i];
  for(int i=0;i<n;i++)
    cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  for(int i=0;i<n;i++) {
    auto x = lower_bound(a.begin(), a.end(), b[i]);
    auto y = upper_bound(c.begin(), c.end(), b[i]);
    ans += (x-a.begin()) * (c.end()-y);
  }
  cout << ans << endl;

}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define pb push_back
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> x,y;
  int t;
  for(int i=0;i<N;i++){
    cin>>t;
    x.pb(t);
  }

  for(int i=0;i<M;i++){
    cin>>t;
    y.pb(t);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  for(int i=x[x.size()-1]+1;i<=y[0];i++){
    if(i>X && i<=Y){
      cout<<"No War"<<endl;
      return 0;
    }
  }
  cout<<"War"<<endl;
  return 0;
}

Measured memory_bytes: 256
from math import *
import numpy as np

N,A,B=map(int,input().split())
X=list(map(int,input().split()))

t=0
for i in range(1,N):
	if (X[i]-X[i-1])*A<=B: t+=(X[i]-X[i-1])*A
	else: t+=B

print(t)


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

int main() {
  int a, b;
  cin >> a >> b;
  if(a * 2 > b || a * 4 < b){
    cout << "No";
  }
  else if((4 * a - b) % 2 == 0){
    if((4 * a - b) / 2 <= a){
      cout << "Yes";
    }
  }
  else{
    cout << "No";
  }
  return 0;
}

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

using namespace std;

#define ll long long
#define rep(i,p,q) for(ll i = p;i < q;i++)

int main(void){
    ll n,m;
    cin >> n >> m;
    vector<ll> goods = vector<ll>(n);
    rep(i,0,n) cin >> goods[i];
    sort(goods.begin(),goods.end(),greater<ll>());
    ll sumA = 0;
    rep(i,0,n) sumA += goods[i];
    if(goods[m - 1] < sumA / (double)(4*m)) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
#define minn(x,y) x=min(x,y)
#define maxx(x,y) x=max(x,y)
using namespace std;
int main()
{
	int i,j,k,n,m,x,y,z;
	scanf("%d%d",&n,&k);
	string s;
	cin>>s;
	x=0;
	for(i=1;i<n;i++)
	{
		if(s[i-1]!=s[i])
		{
			x++;
		}
	}
	y=x;
	if(k*2<=x)
	{
		x-=k*2;
	}
	else
	{
		if(x%2==0)
		{
			x=0;
		}
		else
		{
			x=1;
		}
	}
	if(x==1&&(k-1)*2>=y-1)
	{
		x=0;
	}
	printf("%d",n-1-x);
}


Measured memory_bytes: 512
#include <stdio.h>
#define INF 1000000
#define N 100
#define NIL -1
#define white 0
#define black 1
#define gray 2

int n,M[N][N];

void D(){
  int a[N];
  int color[N];
  int minv,u,i,j;

  for(i=0;i<n;i++){
    a[i]=INF;
    color[i]=white;
  }
  a[0]=0;
  color[0]=gray;

  while(black){
    minv=INF;
    u=NIL;
    for(i=0;i<n;i++){
      if(color[i]!=black && a[i]<minv){
	minv=a[i];
	u=i;
      }
    }

    if(u==NIL)break;
    color[u]=black;

    for(j=0;j<n;j++){
      if(color[j]!=black && M[u][j]!=INF){
	if(a[u]+M[u][j]<a[j]){
	  a[j]=a[u]+M[u][j];
	  color[j]=gray;
	}
      }
    }
    
  }
  for(i=0;i<n;i++){
    a[i]=(a[i]==INF)?-1:a[i];
       printf("%d %d\n",i,a[i]);
  }
 
}




int main(){
  int i,j;
  int a,b;
  int c,d;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d%d",&c,&d);
      M[a][c]=d;
    }

  }
  D();
  
  return 0;
}
  




Measured memory_bytes: 2104
/*
      author : nishi5451
      created: 12.08.2020 15:29:44
*/

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


int main(){
    int n;
    cin >> n;
    cout << (n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python

from sys import stdin, stderr

def check(A, B):
   S = set(B)

   # check each row
   for r in xrange(3):
      cnt = 0
      for c in xrange(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True

   # check each colum
   for c in xrange(3):
      cnt = 0
      for r in xrange(3):
         if A[r][c] in S:
            cnt += 1
      if cnt == 3:
         return True

   # check back diagonal
   cnt = 0
   for i in xrange(3):
      if A[i][i] in S:
         cnt += 1
   if cnt == 3:
      return True

   # check forward diagonal
   cnt = 0
   for i in xrange(3):
      if A[i][2-i] in S:
         cnt += 1
   if cnt == 3:
      return True

   return False

def main():
   A = []
   A.append( map(int, stdin.readline().split()) )
   A.append( map(int, stdin.readline().split()) )
   A.append( map(int, stdin.readline().split()) )

   N = int(stdin.readline())
   B = []
   for i in xrange(N):
      B.append( int(stdin.readline()) )

   print 'Yes' if check(A, B) else 'No'

   return 0

if __name__ == '__main__': main()


Measured memory_bytes: 2696