akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,h,w,i,sx,sy;
char e[nmax],f[nmax];
int ss(char c,char c1)
{
	int d,x=0,i;
	if(c=='L')d=sy;
	if(c=='R')d=w-sy+1;
	if(c=='U')d=sx;
	if(c=='D')d=h-sx+1;
	for(i=1;i<=n;i++)
	{
		if(e[i]==c)x++;
		if(x==d)return 1;
		if(f[i]==c1)
		{
			if(c=='L' && sy-(x-1)<=w)x--;
			if(c=='R' && sy+(x-1)>=1)x--;
			if(c=='U' && sx-(x-1)<=h)x--;
			if(c=='D' && sx+(x-1)>=1)x--;
		}
	}
	return 0;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>h>>w>>n>>sx>>sy;
	for(i=1;i<=n;i++)cin>>e[i];
	for(i=1;i<=n;i++)cin>>f[i];
	if(ss('L','R')|ss('R','L')|ss('U','D')|ss('D','U'))cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        int ans = -1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if(i == j) continue;
                if(ans <= v[i]+v[j] && v[i]+v[j] <= m) ans = v[i]+v[j];
            }
        }
        if(ans == -1) puts("NONE");
        else cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

int main(){
    int N, M, check[3] = {0,0,0};
    cin >> N >> M;
    int s[M], c[M], ans[N];
    for(int i = 0; i < N; i++) ans[i] = 0;
    for(int i = 0; i < M; i++){
        cin >> s[i] >> c[i];
        if(check[s[i]-1] == 0 && ans[s[i]-1] == 0) ans[s[i]-1] = c[i];
        else if(ans[s[i]-1] == c[i]) ans[s[i]-1] = c[i];
        else{
            cout << -1 << endl;
            return 0;
        }
        check[s[i]-1] = 1;
    }
    if(N == 1 && ans[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    if(check[0] == 0) ans[0] = 1;
    if(ans[0] == 0) cout << -1 << endl;
    else{
        int answer = 0;
        for(int i = 0; i < N; i++) answer += ans[i] * pow(10,N-i-1);
        cout << answer << endl;
    }
    return 0;
}

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

int main (void){
    int H,W;
    cin >> H >> W;
    string S[H+10];
    for(int i=0;i<H;i++){
        cin >> S[i] ;
    }
    const int dx[8] = {1,0,-1,0,1,-1,-1,1};
    const int dy[8] = {0,1,0,-1,1,1,-1,-1};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j] == '.'){
                int count=0;
                for(int k=0;k<8;k++){
                    int ni = i + dy[k];
                    int nj = j + dx[k];
                    if(ni<0 || ni >= H) continue;
                    if(nj<0 || nj >= W) continue;
                    if(S[ni][nj] == '#') count++;
                }
                //int -> charへのキャスト　charの末尾に'0'をつける
                //https://marycore.jp/prog/c-lang/convert-number-to-char/
                S[i][j] = char(count + '0');
            }
        }
    }
    for(int i=0 ;i<H;i++){
        cout << S[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            int c=n-(i*j);
            if(c<=0)
                break;
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	

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

		int n = Integer.parseInt(sc.next());

		if(n % 2 == 0) {
			System.out.println(n / 2);
		}else{
			
			System.out.println((n /2) + 1);
		}
		
		
		
	}
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void sublime(){ 
    #ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
      }
vector<ll>ans;
template<typename T>
class graph
  {
    public:
    map<T, vector<T>>g;
    void addedge( T u, T v, bool bidir=true)
    {
        g[u].push_back(v);
        if(bidir)
        {
            g[v].push_back(u);
        }
    }
   void countconnected(T src)
   {
    map<T, bool>visited;
    int count=0;
    for(auto i : g)
    {  T node= i.first;
        if(!visited[node])
        {
            count++;
            bfs(node, visited);
        }
    }
    //cout<<"Total connected component "<<count<<'\n';
   }
   void bfs(T src, map<T, bool> &visited)
   {
     queue<T>q;
     q.push(src);
     visited[src]=true;
     ll aa=0;
     while(!q.empty())
     { 
        T node=q.front();
        aa++;
        q.pop();
        for(auto nbr: g[node])
        {
          if(!visited[nbr])
            { 
             q.push(nbr);
             visited[nbr]=true;
            }
        }
     }
     ans.push_back(aa);
   }
};

int main()
{   
   // sublime();
    graph<ll>g;
    ll n,m;
    cin>>n>>m;
    
    int flag=0;
    ll start;
    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        if(flag==0)
        { 
            start=a;
            flag=1;
        }
        g.addedge(a,b);

    }
    g.countconnected(start);
    ans.push_back(1);
    sort(ans.begin(), ans.end());
    ll sum=0;
    for(ll i=0; i<ans.size(); i++)
    {
        ans[i]-=sum;
        sum+=ans[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 40664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		if(n != 100) System.out.println(n*(int)Math.pow(100,d));
		else System.out.println((n+1)*(int)Math.pow(100,d));
		sc.close();
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <string.h>
#define max 1001
void LCSLength(char *, char*); /* 最長共通分列の長さを求める。*/
char text1[max], text2[max];
int q, c[max+1][max+1];
int main()
{
  int i;

  scanf("%d",&q);
    
  for(i = 0 ; i < q ; i++){ 
    scanf("%s",text1);
    scanf("%s",text2);
    LCSLength(text1, text2);
    printf("%d\n",c[strlen(text1)][strlen(text2)]); }

  return 0;
}

void LCSLength(char *X, char *Y)
{
  int i, j, m, n;
  
  m = strlen(X); /* 文字列Xの長さを測る。*/
  n = strlen(Y); /*文字列Yの長さを測る。*/

  for(i = 0 ; i <= m ; i++) c[i][0] = 0;
  for(j = 0 ; j <= n ; j++) c[0][j] = 0;

  for(i = 1 ; i <= m ; i++){
    for(j = 1 ; j <= n ; j++){
      if(X[i-1] == Y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1]; }
  }

}



Measured memory_bytes: 5708
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int n;
vi vec;

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

    cin>>n;
    vec.resize(n);
    rep(i,n)
        cin>>vec[i];

    sort(all(vec));

    int tgt=vec[n-1];
    int difft=tgt/2;
    int diff;
    int mn=INF;
    int ansi=0;
    rep(i,n){
        diff=abs(difft-vec[i]);
        if(mn>=diff){
            ansi=i;
            mn=diff;
        }
    }
    if(n-1==ansi) ansi--;
    cout<<vec[n-1]<<" "<<vec[ansi]<<endl;

    return 0;
}

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

struct Node {
    int key;
    Node *p_parent;
    Node *p_left;
    Node *p_right;
};
Node *p_r;
Node *NIL;
int m;

void insert( Node *p_z ) {
    Node *p_x = p_r;
    Node *p_y = NIL;

    while ( p_x != NIL ) {
	p_y = p_x;
	if ( p_z->key < p_x->key ) {
	    p_x = p_x->p_left;
	}
	else {
	    p_x = p_x->p_right;
	}
    }

    p_z->p_parent = p_y;
    if ( p_y == NIL ) p_r = p_z;
    else if ( p_z->key < p_y->key ) p_y->p_left = p_z;
    else p_y->p_right = p_z;

}

void preOrder(Node *p_cur) {
    if ( p_cur == NIL ) return;

    printf( " %d", p_cur->key );
    preOrder( p_cur->p_left );
    preOrder( p_cur->p_right );

    return;
}



void inOrder(Node *p_cur) {
    if ( p_cur == NIL ) return;
    inOrder( p_cur->p_left );
    printf( " %d", p_cur->key );
    inOrder( p_cur->p_right );

    return;
}

int main()
{
    scanf("%d", &m);

    for ( int i = 0; i < m; i++ ) {
	char str[100];

	scanf(" %s", str);

	if ( str[0] == 'i' ) {
	    int d;
	    Node *p_z = (Node *)malloc( sizeof(Node) );
	    scanf("%d", &d);

	    p_z->p_parent = p_z->p_left = p_z->p_right = NIL;
	    p_z->key = d;
	    insert( p_z );
	}
	else {
	    inOrder(p_r);
	    printf("\n");
	    preOrder(p_r);
	    printf("\n");
	}
    }

    return 0;
}

Measured memory_bytes: 24468
#include<iostream>
using namespace std;
string s;
long cnt[2019];
main()
{
	cin>>s;
	int now=0;
	long ans=0,p=1,pi=1;
	cnt[0]=1;
	for(int i=s.size();i--;)
	{
		now=(now+(s[i]-'0')*p)%2019;
		ans+=cnt[now]++;
		p=p*10%2019;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3776
package main

import (
	"fmt"
	"io"
	"os"
)

const Mod = 1000000007

func main() {
	r := NewScannerSize(os.Stdin, 1024*1025)
	h, w := r.Int(), r.Int()

	grid := make([][]byte, h)
	for i := 0; i < h; i++ {
		grid[i] = r.UnsafeBytes()
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] != '.' {
				continue
			}
			if i == 0 && j == 0 {
				dp[i][j] = 1
				continue
			}
			if i == 0 {
				dp[i][j] = dp[i][j-1]
				continue
			}
			if j == 0 {
				dp[i][j] = dp[i-1][j]
				continue
			}

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	fmt.Println(dp[h-1][w-1])
}

// generated by https://github.com/murosan/gollect

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScannerSize(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size, start: size, end: size,
	}
}

func (s *Scanner) UnsafeBytes() []byte { return s.bytes() }

func (s *Scanner) Int() int { return ParseInt(s.bytes()) }

func (s *Scanner) bytes() []byte { b, _ := s.next(); return b }
func (s *Scanner) next() (b []byte, size int) {
	for n := 0; ; {
		for i := s.end; i < s.size; i++ {
			if s.buf[i] == s.delim || s.buf[i] == '\n' || i == s.eof {
				b, size = s.buf[s.start:i], i-s.start
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		if n++; n == 2 {
			panic("lack of buffer size")
		}
		s.read()
	}
}
func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}


Measured memory_bytes: 9472
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

pi, qi = -1, -1
for i, perm in enumerate(permutations(range(1, n + 1))):
    if perm == p:
        pi = i
        if qi != -1:
            break
    if perm == q:
        qi = i
        if pi != -1:
            break
print(abs(pi - qi))


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    int K, S;
    cin >> K >> S;
    ll ans = 0;
    for (int X = 0; X <= K; X++) {
        for (int Y = 0; Y <= K; Y++) {
            if (S - X - Y < 0) continue;
            if (S - X - Y <= K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;

public class Playground
{
    //private static List<string[]> item = new List<string[]>();

    public static void Main(string[] args)
    {
        Input();
        //Method();
        System.Console.ReadLine();
    }

    private static void Input()
    {
        var dic = new HashSet<string>();
        int num = int.Parse(Console.ReadLine());
        var sb = new StringBuilder();
        for (int i = 0; i < num; i++)
        {
            var ope = (Console.ReadLine().Split(' '));
            //if (ope[0][0] == 'i')
            if (ope[0].Equals("insert"))
            {
                dic.Add(ope[1]);
            }
            else
            {
                if (dic.Contains(ope[1]))
                {
                    sb.AppendLine("yes");
                }
                else
                {
                    sb.AppendLine("no");
                }
            }
        }
        Console.Write(sb.ToString());
    }

    //private static void Method()
    //{
    //    //var dic = new Dictionary<int, string>();
    //    var dic = new HashSet<string>();
    //    foreach (var ope in item)
    //    {
    //        if (ope[0].Equals("insert"))
    //        {
    //            dic.Add(ope[1]);
    //        }
    //        else
    //        {
    //            if (dic.Contains(ope[1]))
    //            {
    //                Console.WriteLine("yes");
    //            }
    //            else
    //            {
    //                Console.WriteLine("no");
    //            }
    //        }
    //    }
    //}
}

Measured memory_bytes: 45980
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int main()
{
	int a,b;
	cin>>a>>b;
	int c=a+b;
	if(a%3==0||b%3==0||c%3==0){
		cout<<"Possible";
	}
	else cout<<"Impossible";
    return 0;
}

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

class P
{
    static void Main()
    {
        var a = ReadLine().Split().Select(int.Parse).ToList();
        var s = new List<List<int>>();
        var t = new int[-~a[1]];
        for (int i = 0; i < a[0]; i++)
        {
            s.Add(ReadLine().Split().Select(int.Parse).ToList());
            s[i].Add(s[i].Sum());
            for (int j = 0; j < s[i].Count; j++)
            {
                t[j] += s[i][j];
            }
        }
        s.Add(t.ToList());
        s.ForEach(x => WriteLine(string.Join(" ", x)));
    }
}


Measured memory_bytes: 20416
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n;
	cin>>n;
	map<string,vector<string>> m;
	for(int i = 0; i<n; i++){
		string a;
		cin>>a;
		string b = a;
		sort(all(a));
		m[a].pb(b);
	}
	int ans = 0;
	for(auto p : m){
		int d = p.ss.size();
		ans+=((d*(d-1))/2);
	}
	cout<<ans;
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	end_time();
	return 0;
}

Measured memory_bytes: 20608
n = int(input())
acts = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
a, b, c = acts[0]
dp[0] = [a, b, c]
for i in range(1, n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i][j] = max(dp[i][j], dp[i - 1][k] + acts[i][j])
print(max(dp[-1]))

Measured memory_bytes: 74164
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr double mv[2][4] = {
    { +1, -1, 0, 0 }, { 0, 0, +1, -1 }
};
struct Data { Int axis[2], dir; };
double range(const vector<Data>& D, double t, int axis) {
    double M = -1e9, m = 1e9;
    for (auto &d : D) {
        double x = d.axis[axis] + t * mv[axis][d.dir];
        M = max(M, x);
        m = min(m, x);
    }
    return M - m;
}
double slope(const vector<Data>& D, double t, int axis) {
    return (range(D, t+0.1, axis) - range(D, t, axis)) / 0.1;
}
double func(const vector<Data>& D, double t) {
    return range(D, t, 0) * range(D, t, 1);
}
int main()
{
    int N; cin >> N;
    vector<Data> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i].axis[0] >> D[i].axis[1];
        char c; cin >> c;
        D[i].dir = (c == 'R' ? 0 : c == 'L' ? 1 : c == 'U' ? 2 : 3);
    }
    vector<double> T;
    T.push_back(0);
    for (int axis = 0; axis < 2; axis++) {
        double d = slope(D, 0.25, axis);
        Int curr = 0;
        while (curr < 2e8) {
            Int ok = 2e8, ng = curr;
            while (ok - ng > 1) {
                Int mid = (ok + ng) / 2;
                double t = mid / 2.0 + 0.25;
                (slope(D, t, axis) > d + 0.5 ? ok : ng) = mid;
            }
            T.push_back(ok / 2.0);
            curr = ok;
            d = slope(D, ok / 2.0 + 0.25, axis);
        }
    }
    double ans = 1e18;
    for (auto t : T) {
        ans = min(ans, func(D, t));
    }
    cout << fixed << setprecision(12) << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int k[100005];
int a[100005];
int main(){
  int m,n,b,c=0,w=0;
  string s;
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    k[i]=0;
    a[i]=0;
  }
  for(int i=1;i<=m;i++){
    cin>>b>>s;
    if(s[0]=='A'){
      if(k[b]==0){
	k[b]=1;
	c++;
      }
    }
    else{
      if(k[b]==0){
	a[b]++;
	w++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    if(k[i]==0){
      w-=a[i];
    }
  }
  cout<<c<<" "<<w<<"\n";
  return(0);
}


Measured memory_bytes: 1024
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define m 1000000007 
#define MAXN 100000
using namespace std;
int main(){
    string s;
    cin>>s;
    for(long long int i=0;i<s.length();i++){
        if(s[i]=='7'){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main(){
  int n,c,pi[100],sum,mine,i;
  sum = 0;
  cin >> n >> c;
  for(i=0;i<c;i++){
    cin >> pi[i];
    sum = sum + pi[i];
  }
  if(sum%(n+1)==0) mine = sum/(n+1);
  else mine = sum/(n+1)+1;
  cout << mine << endl;

}



Measured memory_bytes: 3112
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    h,w = LI()
    a = [[c=='#' for c in S()] for _ in range(h)]

    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for di,dj in dd:
                ni = u[0] + di
                nj = u[1] + dj
                if ni < 0 or ni >= h or nj < 0 or nj >= w or a[ni][nj]:
                    continue
                uv = (ni,nj)
                if v[uv]:
                    continue
                vd = k + 1
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

    r = 0
    for i in range(h):
        for j in range(w):
            if a[i][j]:
                continue
            d = search((i,j))
            t = max(d.values())
            if r < t:
                r = t

    return r


print(main())





Measured memory_bytes: 6288
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

P = [a for a in A if a >= 0]
N = [a for a in A if a < 0]

def canPositive():
    for i in range(0, len(N) + 1, 2):
        p = K - i
        if p < 0:
            break
        if len(P) >= p:
            return True
    return False

if not canPositive():
    A.sort(key=lambda a: abs(a))
    ans = 1
    for a in A[:K]:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

if not P or not N or len(A) == K:
    A.sort(key=lambda a: abs(a), reverse=True)
    ans = 1
    for a in A[:K]:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

P.sort(key=lambda a: abs(a))
N.sort(key=lambda a: abs(a))
P = deque(P)
N = deque(N)

ans = 1
sign = 1
while K > 0:
    ans %= MOD
    if ans == 0:
        break
    if K == 1:
        if sign < 0:
            ans *= N.pop()
        else:
            ans *= P.pop()
        break

    if len(P) >= 2 and len(N) >= 2:
        p = P[-1] * P[-2]
        n = N[-1] * N[-2]
        if p > n:
            ans *= P.pop()
            K -= 1
        else:
            ans *= N.pop() * N.pop()
            K -= 2
        continue
    if len(P) <= 1 or len(N) <= 1:
        if len(N) == 0:
            ans *= P.pop()
            K -= 1
            continue

        if len(P) == 0:
            ans *= N.pop()
            K -= 1
            sign *= -1
            continue

        if len(N) == 1:
            n = N.pop()
            if sign < 0:
                ans *= n
                K -= 1
                sign *= -1
            continue

        if len(P) == 1:
            p = P.pop()
            if K % 2 == 1 and sign > 0 or K % 2 == 0 and sign < 0:
                ans *= p
                K -= 1
            continue

print(ans % MOD)


Measured memory_bytes: 33544
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}



void __sol(){
    
    char c; cin >> c;
    if(c>='A' && c<='Z') cout << "A";
    else cout << "a";
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    vector<int> n(3);
    for(int i=0;i<3;i++)cin>>n[i];
    sort(n.begin(),n.end());
    reverse(n.begin(),n.end());
    cout<<n[0]*10+n[1]+n[2]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};


int main(){
    int n;cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        if(i % 2 == 0 && a % 2) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y=0,z,n,m=0,k,h,w,sum=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> s;
    n = s.size();
    rep(i,n){
        if(y==0 && s[i]=='T'){
            continue;
        }
        else if(s[i]=='S'){
            y++;
        }
        else if(y>0 && s[i]=='T'){
            ans+=2;
            y--;
        }
    }
    if(n-ans > 0) cout << n - ans << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 640
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int u[101][101];

int main(){
  scanf("%d", &n);
  if(n % 2){
    for(int i = 1; i < n; ++i){
      u[i][n - i] = 1;
    }
  } else{
    for(int i = 1; i <= n; ++i){
      u[i][n - i + 1] = 1;
    }
  }
  int cnt = 0;
  for(int i = 1; i <= n; ++i){
    for(int j = i + 1; j <= n; ++j){
      cnt += u[i][j] == 0;
    }
  }
  printf("%d\n", cnt);
  for(int i = 1; i <= n; ++i){
    for(int j = i + 1; j <= n; ++j){
      if(!u[i][j]){
        printf("%d %d\n", i, j);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
N,*as=$<.read.split.map(&:to_i)
as = as.map.with_index.sort_by {|a,i|-a}

dp = [0] * (N+1)

N.times do |i|
  a,idx = as[i]
  dp_ = [0] * (N+1)
  0.upto(i) do |j|
    dp_[j+1] = dp[j]+a*(idx-j).abs
    dp_[j] = [dp_[j], dp[j]+a*(N-1-i-(idx-j)).abs].max
  end
  dp = dp_
end

puts dp.max


Measured memory_bytes: 42288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e9;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n+1];
    for(ll i=1;i<=n;i++){cin>>h[i];}
    ll ans[n+1];
    for(ll i=1;i<=n;i++) ans[i]=inf;
    ans[1]=0;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            if((i-j)>=1)
            {
                ans[i]=min(ans[i],ans[i-j]+abs(h[i]-h[i-j]));
            }
            else
            {
                break;
            }
        }
    }
    cout<<ans[n]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K, max_path=0, idx=-1;
  std::cin >> N >> K;
  std::vector<ll> path(N-1);
  std::vector<ll> A(N);
  for(int i=0;i<N;i++){
    std::cin >> A[i];
    if(i!=0) {
      path[i-1] = A[i] + A[i-1];
      if(max_path<path[i-1]) max_path=path[i-1], idx=i-1;
    }
  }
  if(max_path<K){
    std::cout << "Impossible" << '\n';
    return 0;
  }
  std::cout << "Possible" << '\n';
  std::vector<int> ans;
  for(int i=0;i<N-1;i++){
    if(i!=idx) ans.push_back(i+1);
    else break;
  }
  for(int i=N-2;i>=0;i--){
    if(i!=idx) ans.push_back((i+1));
    else break;
  }
  ans.push_back(idx+1);
  for(int i=0;i<ans.size();i++) std::cout << ans[i] << endl;
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
struct SegTree {
	int n;
	std::vector<int> data;
	SegTree (int n_) {
		for (n = 1; n < n_; n <<= 1);
		data.resize(n << 1);
	}
	void add(int i, int val) {
		for (i += n; i; i >>= 1) data[i] += val;
	}
	int sum(int l, int r) {
		int res = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) res += data[--r];
			if (l & 1) res += data[l++];
		}
		return res;
	}
};

int main() {
	int n = ri();
	int q = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	std::map<int, std::vector<int> > index;
	for (int i = 0; i < n; i++) index[a[i]].push_back(i);
	
	struct Info {
		int l;
		int r;
		int val;
	};
	std::vector<Info> add[n + 1];
	
	for (auto &i : index) {
		auto x = i.second;
		i.second.push_back(n);
		int last = 0;
		for (auto j : i.second) {
			add[last].push_back({last, j, 1});
			add[j].push_back({last, j, -1});
			last = j + 1;
		}
	}
	
	std::vector<std::pair<int, int> > qs[n];
	for (int i = 0; i < q; i++) {
		int l = ri() - 1;
		int r = ri() - 1;
		qs[l].push_back({r, i});
	}
	SegTree tree(n + 1);
	int res[q];
	for (int i = 0; i < n; i++) {
		for (auto j : add[i]) {
			tree.add(j.l, j.val);
			tree.add(j.r, -j.val);
		}
		for (auto j : qs[i]) res[j.second] = index.size() - tree.sum(0, j.first + 1);
	}
	for (auto i : res) printf("%d\n", i);
	
	return 0;
}


Measured memory_bytes: 127376
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

//---------------------------------------------
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.resize(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int N,K,L;
    cin >> N >> K >>L;
    
    UnionFind UFK(N),UFL(N);

    rep(i,K) {
        int p,q;
        cin >> p >> q;
        p--;
        q--;
        UFK.merge(p,q);
    }
    rep(i,L) {
        int r,s;
        cin >> r >> s;
        r--;
        s--;
        UFL.merge(r,s);
    }

    map<pair<ll,ll>,int> m;

    rep(i,N) {
        m[{UFK.root(i),UFL.root(i)}]++;
    }
    rep(i,N) {
        cout << m[{UFK.root(i),UFL.root(i)}] << " ";
    }
    cout << endl;

}

Measured memory_bytes: 18048
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, d;
  cin >> n >> d;
  vector<ll> x(n), y(n);
  int cnt = 0;
  rep(i, n) {
    cin >> x[i] >> y[i];
    if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;

	ll k = __gcd(n, m);
	for (ll i = 0, j = 0; i < n && j < m; i += n / k, j += m / k) {
		if (s[i] != t[j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << n * m / k << endl;
}


Measured memory_bytes: 3800
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) {
        ll low = i * (i - 1) / 2;
        ll high = n * i - low;
        (ans += high - low + 1) %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int;

int main() {

	int n, k;
	while (cin >> n >> k, n ) {
		vector <ll> a(n);
		for (int i = 0; i < n; i++)cin >> a[i];

		vector<ll> s(n + 1, 0);
		for (int i = 0; i < n; i++) {
			s[i + 1] = s[i]+a[i];
		}

		ll res = -100000000001;

		for (int i = 0; i <= n - k ; i++) {
			ll sum = s[i + k] - s[i];
			res = max(res, sum);
			
		}
		cout << res << endl;
	}


	return 0;
}



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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    set<char> s1, s2;
    vector<char> result;
    for (char c : s.substr(0, i)) s1.insert(c);
    for (char c : s.substr(i, s.size() - i)) s2.insert(c);
    set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(result));
    ans = max(ans, static_cast<int>(result.size()));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
  var N,M int
  fmt.Scan(&N)
  s := make([]string, N)
  m := make(map[string]int)
  for i:=0;i<N;i++{
    fmt.Scan(&s[i])
    m[s[i]] +=1
  }
  fmt.Scan(&M)
  t := make([]string,M)
  for i:=0;i<M;i++{
    fmt.Scan(&t[i])
    m[t[i]] -=1
  }
  result := 0
  for _,v:= range m{
    if v > result{
      result = v
    }
  }
  fmt.Println(result)
}


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


void solve(long long A, long long B, long long Q, std::vector<long long> s, std::vector<long long> t, std::vector<long long> x){
    s.push_back(-10000000000000LL);
    t.push_back(-10000000000000LL);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    for (int i = 0; i < Q; i++) {
        long long answer = 100000000000000LL;
        {
            auto l = lower_bound(s.begin(), s.end(), x[i]);
            auto v1 = *l;
            auto v2 = *(l - 1);
            auto l2 = lower_bound(t.begin(), t.end(), v1);
            auto l3 = lower_bound(t.begin(), t.end(), v2);

            answer = min(abs(x[i] - v1) + abs(v1 - *l2), answer);
            //printf("%d %d %d = %d", x[i], v1, *l2, abs(x[i] - v1) + abs(v1 - *l2));
            //puts("");
            answer = min(abs(x[i] - v1) + abs(v1 - *(l2-1)), answer);
            //printf("%d %d %d = %d", x[i], v1, *(l2-1), abs(x[i] - v1) + abs(v1 - *(l2-1)));
            //puts("");
            answer = min(abs(x[i] - v2) + abs(v2 - *l3), answer);
            //printf("%d %d %d = %d", x[i], v2, *l3, abs(x[i] - v2) + abs(v2 - *l3));
            //puts("");
            answer = min(abs(x[i] - v2) + abs(v2 - *(l3-1)), answer);
            //printf("%d %d %d = %d", x[i], v2, *(l3-1), abs(x[i] - v2) + abs(v2 - *(l3-1)));
            //puts("");
        }
        {
            auto l = lower_bound(t.begin(), t.end(), x[i]);
            auto v1 = *l;
            auto v2 = *(l - 1);
            auto l2 = lower_bound(s.begin(), s.end(), v1);
            auto l3 = lower_bound(s.begin(), s.end(), v2);
            answer = min(abs(x[i] - v1) + abs(v1 - *l2), answer);
            //printf("%d %d %d = %d", x[i], v1, *l2, abs(x[i] - v1) + abs(v1 - *l2));
            //puts("");
            answer = min(abs(x[i] - v1) + abs(v1 - *(l2-1)), answer);
            //printf("%d %d %d = %d", x[i], v1, *(l2-1), abs(x[i] - v1) + abs(v1 - *(l2-1)));
            //puts("");
            answer = min(abs(x[i] - v2) + abs(v2 - *l3), answer);
            //printf("%d %d %d = %d", x[i], v2, *l3, abs(x[i] - v2) + abs(v2 - *l3));
            //puts("");
            answer = min(abs(x[i] - v2) + abs(v2 - *(l3-1)), answer);
            //printf("%d %d %d = %d", x[i], v2, *(l3-1), abs(x[i] - v2) + abs(v2 - *(l3-1)));
            //puts("");

        }
        printf("%lld\n", answer);
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> s(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&s[i]);
    }
    std::vector<long long> t(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&t[i]);
    }
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&x[i]);
    }
    solve(A, B, Q, std::move(s), std::move(t), std::move(x));
    return 0;
}


Measured memory_bytes: 3680
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

def main():
    N = int(input())
    edges = [[] for _ in range(N)]
    ans = []
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    K = 0
    for i in range(N):
        K = max(K, len(edges[i]))

    visited = [False] * N

    def dfs(v, color):
        visited[v] = True
        for l, m in enumerate(edges[v]):
            if visited[m[0]]:
                continue
            color += 1
            color %= K
            ans.append((m[1],color))
            dfs(m[0], color)

    dfs(0,0)

    ans.sort()
    print(K)
    for a, b in ans:
        print(b+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 112028
#include <iostream>
#include<algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include<map>
#include<set>
#include<sstream>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int maxn=2e4+10;
int f[maxn];
int main()
{
    int n,x,y;cin>>n>>x>>y;
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            int minn=min(j-i,abs(x-i)+1+abs(y-j));
            f[minn]++;
        }
    }
    for(int i=1;i<n;++i)
        cout<<f[i]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

vector<int> sosu;

bool so(int i)
{
	if( i == 1) return false; 
	int max = (int)sqrt((double)i);
	for(vector<int>::iterator it = sosu.begin(); it != sosu.end(); ++it){
		if( max < *it) return true;
		if( i % *it == 0) return false;
	}
	return true;
}

void append(int i)
{
			int max = (int)sqrt((double)i);
		bool isSosu = true;
		for(vector<int>::iterator it = sosu.begin(); it != sosu.end(); ++it){
			if(max < *it) break;
			if(i % *it == 0){ isSosu = false; break;}
		}
			if(isSosu) sosu.push_back(i);
}

int main()
{
	sosu.push_back(2);
	sosu.push_back(3);
	sosu.push_back(5);

	// %6 == 1 or 5
	for(int i = 7; i < 1000; i += 6){
		append(i);
		append(i+4);
	}

	int a,d,n;
	while(cin>>a>>d>>n,(a||d||n)){
		int count = 0,i = a;
		while(true){
			if( so(i)) count++;
			if(count >= n) break;
			i += d;
		}
		cout << i << endl;
	}
}

Measured memory_bytes: 0
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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(void) {
  int n, m;
  cin >> n >> m;
  vector<P> a(n);
  rep(i, n) {
    cin >> a[i].first >> a[i].second;
  }
  vector<P> c(m);
  rep(i, m) {
    cin >> c[i].first >> c[i].second;
  }

  rep(i, n) {
    int dist = 1000000000;
    int ans;
    rep(j, m) {
      int d = abs(a[i].first - c[j].first) + abs(a[i].second - c[j].second);
      if (d < dist) {
        dist = d;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3604
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if((a==b&&a!=c)||(b==c&&a!=b)||(c==a&&a!=b)){
        System.out.println("Yes");
        return;
    }
    System.out.println("No");
  }
  

  
}


Measured memory_bytes: 21716
N = gets.to_i
max_n = 1
max_cnt = 0
(1..N).each do |n|
  cnt = 0
  tmp = n
  while tmp%2==0 do
    tmp/=2
    cnt += 1
  end
  if cnt > max_cnt
    max_n = n
    max_cnt = cnt
  end
end
p max_n

Measured memory_bytes: 1788
#include<stdio.h>
#define ll long long
#define MOD 1000000007

int main(){
	//公差d>0のときm+1-d(n-1)通り
	ll n,m;
	scanf("%lld%lld",&n,&m);
	ll S=m+1-(n-1);
	if(n==1||S<0){
		printf("%lld\n",(m+1)%MOD);
		return 0;
	}
	ll T=S%(n-1);
	ll c=(S-T)/(n-1)+1;
	ll ans=(S+T)%MOD*(c%MOD)%MOD;
	printf("%lld\n",(ans+m+1)%MOD);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char q[102]={0};
	gets(q);
	int sum=0,a=0,b=0;
	for(int i=0;i<strlen(q);i++){
		if(q[i]=='C' && sum==0) {a=i;sum++;
		}
		else if(q[i]=='F' && sum==1){b=i;sum++;
		} 
	}
	if(sum==2 && b>a) cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  ll S;
  cin >> S;
  vector<ll> A(S+1, 0);
  A[0] = 1;
  for (int i=1; i<=S; i++) {
    for (int j=0; j<=i-3; j++) {
      A[i] += A[j]%MOD;
      A[i] %= MOD;
    }
  }
  cout << A[S] << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	char s[100100];
	scanf("%s",s);
	int l=strlen(s);
	if(l%2!=0)
	{
		cout<<"No\n";
		return 0;
	}
	bool f=0;
	for(int i=0;i<l/2;i++)
	{
		if(s[i]=='p'&&s[l-i-1]!='q')
		{
			f=1;break;
		}
		if(s[i]=='q'&&s[l-i-1]!='p')
		{
			f=1;break;
		}
		if(s[i]=='b'&&s[l-i-1]!='d')
		{
			f=1;break;
		}
		if(s[i]=='d'&&s[l-i-1]!='b')
		{
			f=1;break;
		}
	}
	if(!f)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;

int main()
{
	long long int n, x, y, p, q;

	cin >> n;

	vector<pair<long long int,long long int> > v;
	vector <long long int> a, b;

	for (long long int i = 0; i < n; i++)
	{
		cin >> x >> y;
		v.push_back(make_pair(x, y));
		a.push_back(x + y);
		b.push_back(x - y);
	}

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

	p = a[a.size() - 1] - a[0];
	q = b[b.size() - 1] - b[0];

	if (p > q)
	{
		cout << p;
	}
	else
	{
		cout << q;
	}

  	return 0;
}

Measured memory_bytes: 11548
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		new Main().run();
	}
	
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	
	long inv(long a,long M) {
		return a==1?a:(M+(-M*inv(M%a,a)+1)/a);
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();
		if (N==1) {
			System.out.println(1);
			return;
		}
		N*=2;
		long ans=Long.MAX_VALUE;
		for (long d=2;d*d<=N;++d) if (N%d==0) {
			for (long P:new long[] {d,N/d}) {
				long Q=N/P;
				if (gcd(P,Q)!=1) continue;
				ans=Math.min(ans, (inv(P,Q)*P-1)/Q*Q);
			}
		}
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

Measured memory_bytes: 36720