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

using namespace std;
using ll = long long;

vector<string> split(string s) {
  vector<string> ret;
  int bef = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '"') {
      ret.push_back(s.substr(bef, i - bef + 1));
      bef = i + 1;
    }
  }
  if (bef < s.size())
    ret.push_back(s.substr(bef));
  return ret;
}

int main() {
  while (true) {
    string s, t;
    cin >> s;
    if (s == ".")
      break;
    cin >> t;
    if (s == t) {
      cout << "IDENTICAL" << endl;
      continue;
    }
    char *p;
    vector<string> ss = split(s), tt = split(t);
    int c = 0;
    if (ss.size() == tt.size()) {
      for (int j = 0; j < ss.size(); j++) {
        if (ss[j] != tt[j]) {
          if (j % 2 == 1)
            c++;
          else
            c += 2;
        }
      }
    } else {
      c = 100;
    }
    if (c == 1) {
      cout << "CLOSE" << endl;
    } else {
      cout << "DIFFERENT" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3160
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
//		int idx = 0;
		while(true){
			int n = in.nextInt();
			int m = in.nextInt();
			if(n == 0) break;
			int s = in.nextInt()-1;
			int g = in.nextInt()-1;
			boolean[][][] used = new boolean[n][n][31];
			int[][] rist = new int[n][n];
			int[][] dist = new int[n][n];
			Node[] node = new Node[n];
			for(int i=0; i<n; i++) node[i] = new Node(i);
			for(int i=0; i<m; i++){
				int x = in.nextInt()-1;
				int y = in.nextInt()-1;
				int d = in.nextInt();
				int c = in.nextInt();
				node[x].createEdge(node[y]);
				node[y].createEdge(node[x]);
				dist[x][y] = dist[y][x] = d;
				rist[x][y] = rist[y][x] = c;
			}
//			double[][][] best = new double[n][n][31];
			Queue<Pos> qu = new PriorityQueue<Pos>();
			qu.add(new Pos(s, s, 0, 0));
			double time = 1e9;
			while(!qu.isEmpty()){
				Pos p = qu.poll();
				if(p.city == g && p.vel == 1){
					time = p.dist;
					break;
//					time = Math.min(time, p.dist);
				}
//				if(best[p.city][p.back][p.vel] != 0
//						&& best[p.city][p.back][p.vel] <= p.dist) continue;
//				best[p.city][p.back][p.vel] = p.dist;
				if(used[p.city][p.back][p.vel]) continue;
				used[p.city][p.back][p.vel] = true;
				for(Node nd: node[p.city].list){
					if(p.back == nd.id) continue;
					for(int i=-1; i<=1; i++){
						int v = p.vel+i;
						if(v < 1 || v > rist[p.city][nd.id]) continue;
						qu.add(new Pos(nd.id, p.city, v, p.dist + (double)dist[p.city][nd.id]/v));
					}
				}
			}
			System.out.println(time >= 1e9 ? "unreachable" : time);
//			idx++;
		}
	}
}

class Node{
	int id;
	List<Node> list = new ArrayList<Node>();
	public Node(int id){
		this.id = id;
	}
	
	public void createEdge(Node nd){
		list.add(nd);
	}
}

class Pos implements Comparable<Pos>{
	int city;
	int back;
	int vel;
	double dist;
	public Pos(int c, int back, int v, double dist){
		city = c;
		vel = v;
		this.back = back;
		this.dist = dist;
	}
	
	@Override
	public int compareTo(Pos o) {
		return Double.compare(dist, o.dist);
	}
}

Measured memory_bytes: 116804
n = int(input())
dic = dict()
for i in range(n):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s] += 1
m = int(input())
for i in range(m):
    s = input()
    if s not in dic:
        dic[s] = 0
    dic[s] -= 1
ans = list(dic.values())
print(max(max(ans),0))



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,aa,bb;
void go1(int x,int y)
{
    printf("U");
    y++;
    while(x<aa-2)
    {
        printf("R");
        x++;
    }
    while(y!=bb)
    {
        printf("U");
        y++;
    }
    while(x!=aa)
    {
        printf("R");
        x++;
    }
}
void go2(int x,int y)
{
    printf("L");
    x--;
    printf("U");
    y++;
    printf("U");
    y++;
    if(y>bb)
    {
        while(x!=aa)
        {
            printf("R");
            x++;
        }
        printf("D");
        return;
    }
    while(x<aa-3)
    {
        printf("R");
        x++;
    }
    while(y<bb+1)
    {
        printf("U");
        y++;
    }
    while(x<aa)
    {
        printf("R");
        x++;
    }
    printf("D");
}
void back1(int x,int y)
{
    printf("D");
    y--;
    if(aa-a>1)
    {
        printf("L");
        x--;
    }
    while(y!=b)
    {
        printf("D");
        y--;
    }
    while(x!=a)
    {
        printf("L");
        x--;
    }

}
void back2(int x,int y)
{
    printf("R");
    x++;
    printf("D");
    y--;
    printf("D");
    y--;
    if(y<b)
    {
        while(x>a)
        {
            printf("L");
            x--;
        }
        printf("U");
        return;
    }
    if(aa-a>=2)
    {
        printf("L");
        x--;
    }
    while(y!=b-1)
    {
        printf("D");
        y--;
    }
    while(x!=a)
    {
        printf("L");
        x--;
    }
    printf("U");

}
int main()
{
    scanf("%d%d%d%d",&a,&b,&aa,&bb);
    aa=aa-a+1;
    bb=bb-b+1;
    a=1,b=1;
    go1(a,b);
    back1(aa,bb);
    go2(a,b);
    back2(aa,bb);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1000000007;
main(){
    int N,a;
    int cnt[3] = {};//x1,x2,x4
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> a;
        if(a % 4 == 0)cnt[2]++;
        else if(a % 2 == 0)cnt[1]++;
        else cnt[0]++;
    }
    if(cnt[0]){
        if(cnt[1])cnt[0]++;
        if(cnt[0] <= cnt[2]+1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
# B
n = int(input()) 
w = [str(input()) for i in range(n)]
output = 'Yes'

if len(w) != len(set(w)):
    output = 'No'
else:
    for i in range(1, n):
        if w[i][0] != w[i-1][-1]:
            output = 'No'
            break
print(output)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


int main()
{
	ll a, b;
	cin >> a >> b;

	if (a > b) swap(a, b);

	if ((b - a) & 1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << (a + b) / 2 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  if(n==1) {
    cout << "! 1" << endl;
    return 0;
  }
  vector<P> v;
  for(int i=2; i<=n; i++) {
    cout << "? " << 1 << " " << i << endl;
    cout.flush();
    int x;
    cin >> x;
    v.push_back(P(x,i));
  }
  sort(v.begin(),v.end(),greater<P>());
  vector<P> a;
  a.push_back(P(0,v[0].second));
  for(int i=1; i<=n; i++) {
    if(i==v[0].second) continue;
    cout << "? " << v[0].second << " " << i << endl;
    cout.flush();
    int x;
    cin >> x;
    a.push_back(P(x,i));
  }
  sort(a.begin(),a.end());
  cout << "!";
  for(int i=0; i<n; i++) cout << " " << a[i].second;
  cout << endl;
  cout.flush();
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>

using namespace std;

string a,b,c;

int game(int t){

	string s;
	if(t == 0)s = a;
	if(t == 1)s = b;
	if(t == 2)s = c;
	
	if(s.size() > 0){
		char ch = s[0];
		s.erase(s.begin(), s.begin() + 1); 
        
        if(t == 0)a = s;
        if(t == 1)b = s;
        if(t == 2)c = s;
    
		if(ch == 'a')return 0;
		if(ch == 'b')return 1;
		return 2;
	}else{
		if(t == 0)cout << 'A' <<endl;
		if(t == 1)cout << 'B' <<endl;
		if(t == 2)cout << 'C' <<endl;
		
		return -1;
	}
}

int main(){
	cin >> a >> b >>c;

	int t = 0;
	while(t >= 0){
		t = game(t);
	}

	return 0;
}

Measured memory_bytes: 256
n, x, m = [int(e) for e in input().split()]

s = set()
l = []

a = x % m
total = a
for i in range(1, n):
    a = (a * a) % m
    if a == 0:
        break
    
    if a in s:
        r = n - i
        p = l.index(a)
        
        lo_total = 0
        for j in range(p, len(l)):
            lo_total += l[j]
        total += lo_total * (r // (len(l) - p))

        r %= (len(l) - p)        
        for j in range(p, p + r):
            total += l[j]
        break
    
    s.add(a)
    l.append(a)
    total += a

print(total)

Measured memory_bytes: 12776
#include <cstdio>
#include <cstdlib>

int N;
int ti[100010];
int xi[100010];
int yi[100010];

int solve()
{
	int i;
	for(i=0; i<N-1; i++){
		int tmp = abs(xi[i+1]-xi[i]) + abs(yi[i+1]-yi[i]);
		if(tmp%2==(ti[i+1]-ti[i])%2 && tmp<=ti[i+1]-ti[i]){
		}
		else
			return 0;
	}
	return 1;
}

int main()
{
	int i;
	scanf("%d", &N);
	ti[0]=xi[0]=yi[0] = 0;
	for(i=1; i<=N; i++)
		scanf("%d%d%d", &ti[i], &xi[i], &yi[i]);
	N ++;
	if(solve() )
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int n;
int A[21],B[21],C[21];
int ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>A[i];
	for(int i=1;i<=n;i++)
		cin>>B[i];
	for(int i=1;i<n;i++)
		cin>>C[i];
	for(int i=1;i<=n;i++)
	{
		ans+=B[A[i]];
		if(A[i+1]==A[i]+1)
			ans+=C[A[i]];
	}
	cout<<ans<<endl;
	return 0; 
} 

Measured memory_bytes: 256
N,_=gets.chomp.split(' ').map{|n| n.to_i}
icnt = 0
hevn = {}
hodd = {}
gets.chomp.split(' ').map{|n| n.to_i}.each{|i|
	case icnt%2
	when 0
		hevn[i].nil? ? hevn[i] = 1 : hevn[i]+=1
	when 1
		hodd[i].nil? ? hodd[i] = 1 : hodd[i]+=1
	end
	icnt+=1
}
evnsorted = hevn.sort{|a,b| b[1] <=> a[1]}
oddsorted = hodd.sort{|a,b| b[1] <=> a[1]}
# p evnsorted
# p oddsorted
evnmax = evnsorted[0]
oddmax = oddsorted[0]
evnmaxnum = evnmax[1]
oddmaxnum = oddmax[1]
evnmax2num = !evnsorted[1].nil? ? evnsorted[1][1] : 0 
oddmax2num = !oddsorted[1].nil? ? oddsorted[1][1] : 0
if(evnmax[0] == oddmax[0])
	case evnmax2num <=> oddmax2num
	when 1
		evnmaxnum = evnmax2num
	when -1,0
		oddmaxnum = oddmax2num
	end
end
puts "#{N-evnmaxnum-oddmaxnum}"


Measured memory_bytes: 20140
// 20:47~

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

int main()
{
	for(int n,m,p;cin>>n>>m>>p && n|m|p;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		
		vvi d(n,vi(n,INF));
		rep(i,n) d[i][i]=0;
		rep(i,n) for(auto e:g[i]) d[e.src][e.dst]=e.weight;
		rep(k,n) rep(i,n) rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		
		vvd cnt(n,vd(n));
		rep(i,n) for(auto e:g[i])
			if(d[0][e.src]+e.weight+d[e.dst][n-1]==d[0][n-1])
				cnt[e.src][e.dst]=1;
		rep(k,n) rep(i,n) rep(j,n)
			cnt[i][j]+=cnt[i][k]*cnt[k][j];
		
		rep(_,p){
			int c; cin>>c;
			printf("%.9f\n",cnt[0][c]*cnt[c][n-1]/cnt[0][n-1]);
		}
	}
}

Measured memory_bytes: 1500
def gcd(a, b):
    if not a:
        # a が ゼロ ならば b
        return b
    if not b:
        # b が ゼロ ならば a
        return a
    while b:
        a, b = b, a % b
    return a


def main():
    N, *A = map(int, open(0).read().split())
    A.insert(0, 0)
    A.append(0)
    L = [0] * (N + 2)
    R = L[:]
    for i in range(1, N):
        L[i + 1] = gcd(L[i], A[i])
    for i in range(N, 0, -1):
        R[i] = gcd(R[i + 1], A[i])
    print(max(gcd(L[i], R[i + 1]) for i in range(1, N + 1)))
    return


main()


Measured memory_bytes: 14476
#include <iostream>
#include <vector>
int main(){
    int n,q;long k;
    std::cin >> n >> k >> q;
    std::vector<long> a(n, k);
    int t;
    for(int i = 0; i < q; i++){
        std::cin >> t;
        a[t-1]++;
    }
    for(int i = 0; i < n; i++){
        if((a[i]-q) > 0)std::cout << "Yes" << std::endl;
        else std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
 
struct dice{
           int a[6];
       };
struct dice dice1;
struct dice dice2;
 
void tate(){
            int cmp=dice2.a[0];
            dice2.a[0]=dice2.a[4];
            dice2.a[4]=dice2.a[5];
            dice2.a[5]=dice2.a[1];
            dice2.a[1]=cmp;
             }
void yoko(){
            int cmp=dice2.a[1];
            dice2.a[1]=dice2.a[2];
            dice2.a[2]=dice2.a[4];
            dice2.a[4]=dice2.a[3];
            dice2.a[3]=cmp;
             }
 
 
int main(){
    int i,j;
    for(i=0;i<6;i++){
           scanf("%d",&dice1.a[i]);
                     }
for(i=0;i<6;i++){
           scanf("%d",&dice2.a[i]);
                     }
 
for(i=0;i<5;i++){
 
              for(j=0;j<5;j++){
                              if(dice1.a[0]==dice2.a[0])break;
                               tate();
                               }
              for(j=0;j<5;j++){
                                if(dice1.a[1]==dice2.a[1])break;
                                yoko();
                                }
                  }
 
if(dice1.a[0]==dice2.a[0]&&dice1.a[1]==dice2.a[1]&&dice1.a[2]==dice2.a[2])printf("Yes\n");
else printf("No\n");
  
return 0;
}


Measured memory_bytes: 1968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


int S[2009];
int T[2009];
ll dp[2009][2009]; // dp[i][j] : Sの1からi,Tの1からjまでの中の共通部分列の数

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

	int N, M; cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> S[i];
	for (int j = 1; j <= M; j++) cin >> T[j];
	
	for (int j = 0; j <= M; j++) dp[0][j] = 1;
	for (int i = 0; i <= N; i++) dp[i][0] = 1;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			dp[i][j] = MOD + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			if (S[i] == T[j]) dp[i][j] += dp[i - 1][j - 1];
			dp[i][j] %= MOD;
		}
	}

	cout << dp[N][M] << endl;

	return 0;
}

Measured memory_bytes: 31744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i = 0; i < 3000; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (x == 0 && y == 0) {
                return;
            }
            if(x > y) {
                System.out.println(y + " " + x);
            } else {
                System.out.println(x + " " + y);
            }
        }
    }
}


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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double ans = 0.0;
    for(int i = 1; i <= N; i++) {
        for(int j = i + 1; j <= N; j++) ans += dist(i, j) * 2 / N;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j,ans1,ans2;
    for(;;){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(i=1;i<=H;i++){
            ans1=i/2*2;
            for(j=1;j<=W;j++){
                ans2=j/2*2;
                if((ans1!=i)!=(ans2!=j)){
                    cout<<".";
                }else{
                    cout<<"#";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
        return 0;
    }


Measured memory_bytes: 3080
N = int(input())
a = list(map(int,input().split()))

ans = 0
count = 1
cc = 0
for i in range(N):
    if a[i] == count:
        count += 1
        cc += 1
if count == 1:
    print(-1)
elif cc == N:
    print(0)
else:
    print(N-count+1)

Measured memory_bytes: 26268
ai = lambda: list(map(int,input().split()))

h,w = ai()
m = ''
for _ in range(h):
    m += input()

from collections import Counter
k = list(Counter(m).values())

c1 = 0
c2 = 0
for kk in k:
    if kk % 2:
        c1 += 1
        kk -= 1
    if kk % 4:
        c2 += 1

ans = 0
if h&1 and w&1:
    if c1 <= 1 and c2 <= h//2 + w/2:
        ans = 1
elif h&1:
    if c1 <= 0 and c2 <= w//2:
        ans = 1
elif w&1:
    if c1 <= 0 and c2 <= h//2:
        ans = 1
else:
    if c1 <= 0 and c2 <= 0:
        ans = 1

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

vvmint mul(vvmint a, vvmint b, ll N) {
	vvmint ret(N, vmint(N, 0));
	rep(i, N)rep(j, N)rep(k, N) {
		ret[i][j] += a[i][k] * b[k][j];
	}

	return ret;
}

vvmint pow(vvmint a, ll N, ll K) {
	if (K == 0) {
		vvmint ret(N, vmint(N, 0));
		rep(i, N) ret[i][i] = 1;
		return ret;
	}

	vvmint X = pow(a, N, K/2);

	if (K % 2 == 1) {
		return mul(a, mul(X, X, N), N);
	}

	return mul(X, X, N);
}


int main() {
	ll N, K;
	cin >> N >> K;

	vvmint a(N, vmint(N, 0));
	rep(i, N)rep(j, N) {
		ll c;
		cin >> c;
		a[i][j] = c;
	}

	a = pow(a, N, K);
	//rep(i, N)rep(j, N) cout << a[i][j] << endl;

	mint ans = 0;
	rep(i, N)rep(j, N)ans += a[i][j];
	cout << ans << endl;
}



Measured memory_bytes: 4948
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int a, b, c; cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector <int> b(n);
	vector <int> a;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	int i = b.size()-1;
	while (1) {
		if (i < 0) {
			cout << -1 << endl;
			return 0;
		}
		if (i + 1 == b[i]) {
			a.emplace_back(b[i]);
			b.erase(b.begin()+i);
			if (b.size() == 0)break;
			i = b.size() - 1;
			continue;
		}
		i--;
	}

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


	return 0;
}

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

using namespace std;

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

  vector<pair<int, int>> tasks(n);
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    tasks[i] = make_pair(a, b);
  }

  sort(tasks.begin(), tasks.end(), [](pair<int, int> a, pair<int, int> b){
    return a.second < b.second;
  });

  long long int sum = 0;
  bool possible = true;

  for (auto p : tasks) {
    sum += p.first;
    if (p.second < sum) {
      possible = false;
      break;
    }
  }

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

  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int sen =  N / 1000;
    int ans = 0;
    if(N % 1000 == 0) ans = 0;
    else if(sen == 0) ans = 1000 -N ;
    else ans = 1000*(sen+1) - N;
    System.out.println(ans);
  }
}

Measured memory_bytes: 35800
N, M = map(int, input().split())
to = [[] for _ in range(N)]
ans = [-1] * N
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

from collections import deque

Q = deque([0])
ans[0] = -2

while Q:
    v = Q.popleft()
    for s in to[v]:
        if ans[s] == -1:
            ans[s] = v
            Q.append(s)
print("Yes")
print(*(a + 1 for a in ans[1:]), sep="\n")

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

int main() {
	ll n;
	cin>>n;
	ll a[n+1];
	ll b[n+1];
	map< ll , ll > m;
	bool open[n+1];
	memset(open, true, sizeof(open));
	ll temp = 1;
	for(ll i = 1; i<=n; i++){
	    temp = temp * i;
	    m.insert(make_pair(i,temp));
	}
	
	for(ll i=1; i<=n; i++){
	    cin>>a[i];
	}
	for(ll i=1; i<=n; i++){
	    cin>>b[i];
	}
	
	ll a_rank = 0;
	for(ll i=1; i<=n; i++){
	    ll count = 0;
	    for(ll j=1; j<=a[i]; j++){
	        if(open[j])
	            count++;
	    }
	    a_rank += (count * m[n-i]);
	    open[a[i]] = false;
	}
	ll b_rank = 0;
	memset(open, true, sizeof(open));
	
	for(ll i=1; i<=n; i++){
	    ll count = 0;
	    for(ll j=1; j<=b[i]; j++){
	        if(open[j])
	            count++;
	    }
	    b_rank += (count * m[n-i]);
	    open[b[i]] = false;
	}
	cout<<abs(a_rank - b_rank);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N,K;
    cin >> N >> K;
    
    int h[100001];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    sort(h,h+N,greater<int>());
    
    int ans = 0;
    for(int i=0;i<N;i++){
        if(h[i]>=K){
            ans++;
        }else{
            cout << ans << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
	int a, b, c;
	ignore = scanf("%d %d %d", &a, &b, &c);
	
	long long ans = min(b, c);
	b -= ans;
	c -= ans;
	ans *= 2;
	
	int f = min(a, c);
	ans += f;
	a -= f;
	c -= f;
	
	ans += b + min(c, 1);
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    a = collections.deque(list(str(input().rstrip('\n'))))
    b = collections.deque(list(str(input().rstrip('\n'))))
    c = collections.deque(list(str(input().rstrip('\n'))))
    q = "a"
    while True:
        if q == "a":
            if len(a) != 0:
                q = a.popleft()
            else:
                print("A")
                exit()
        elif q == "b":
            if len(b) != 0:
                q = b.popleft()
            else:
                print("B")
                exit()
        elif q == "c":
            if len(c) != 0:
                q = c.popleft()
            else:
                print("C")
                exit()



if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main(){
    int A;
    cin >> A;
    if(A%7==1){
        cout<<"fri"<<endl;
    }
    if(A%7==2){
        cout<<"sat"<<endl;
    }
    if(A%7==3){
        cout<<"sun"<<endl;
    }
    if(A%7==4){
        cout<<"mon"<<endl;
    }
    if(A%7==5){
        cout<<"tue"<<endl;
    }
    if(A%7==6){
        cout<<"wed"<<endl;
    }
    if(A%7==0){
        cout<<"thu"<<endl;
    }
    return 0;
}


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

def main():
    K = int(input())

    if( K % 2 == 0 or K % 5 == 0):
        print(-1)
        return        

    x = 7
    first = True
    flag = False
    for i in range(1000000):
        if(first):
            x = 7
            first = False
        else:
            #x = (x * 10) + 7
            x = (x * 10)%K + 7%K
        
        if(x % K == 0):
            print(i+1)
            flag = True
            break
    
    if(flag != True):
        print(-1)


if __name__ == "__main__":
    main()
    


Measured memory_bytes: 9184
K, T = map(int, input().split())
A = max(map(int, input().split()))
if A <= K // 2 + K % 2:
    print(0)
elif T == 1:
    print(K-1)
elif K % 2 == 0:
    print((A - K // 2) * 2 - 1)
else:
    print((A - K // 2 + 1) * 2)


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    	Scanner scanner=new Scanner(System.in);

    	String input=scanner.next();

    	int first=0;
    	int last=0;

    	for(int i=0;i<input.length();i++) {
    		if(input.charAt(i)=='A') {
    			first=i;
    			break;
    		}
    	}

    	for(int i=input.length()-1;i>=0;i--) {
    		if(input.charAt(i)=='Z') {
    			last=i;
    			break;
    		}
    	}



    	int result=last-first+1;

    	System.out.println(result);

    	scanner.close();


    }

}

Measured memory_bytes: 26544
#include <bits/stdc++.h>
#define INF
#define endl '\n'

using namespace std;
void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n;
string s, s2;
int a[100001];
int dp[1001][1001];

int solve(int a, int b)
{
    //cout << a << " " << b << endl;
    if (a < 0)
        return b+1;
    if (b < 0)
        return a+1;

    int &ret = dp[a][b] ;
    if(~ret)    return ret ; 

    ret = min(solve(a - 1, b) + 1 ,
               min(solve(a, b - 1) +1 ,
                   solve(a - 1, b - 1) + (s[a] != s2[b] ) )) ;
    return ret ; 
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast();

    memset(dp, -1, sizeof dp);
    cin>>s>>s2;
    cout << solve(s.length() - 1, s2.length() - 1)<<endl ;

    return 0;
}




Measured memory_bytes: 7200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int W=sc.nextInt(),H=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(),r=sc.nextInt();
		if(x-r<0||x+r>W){
			System.out.println("No");
		}else if(y-r<0||y+r>H){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	vector<ll> a(n+1);REP(i, n+1)cin >> a[i];
	vector<ll> b(n);REP(i, n)cin >> b[i];

	ll ans = 0;
	REP(i, n){
		ll tmp = min(a[i], b[i]);
		ans += tmp;
		b[i] -= tmp;
		tmp = min(b[i], a[i+1]);
		ans += tmp;
		a[i+1] -= tmp;
	}

	cout << ans << endl;

	return 0;
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v) {
    vi dp(100100, inf);
    dp[0] = 0;

    rep(i, N) rep(jj, 100100) {
        int j = 100100 - 1 - jj;
        if (j - v[i] >= 0) {
            chmin(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    rep(i, 100100) if (dp[100099 - i] <= W) {
        cout << 100099 - i << endl;
        return;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long W;
    scanf("%lld", &W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &w[i]);
        scanf("%lld", &v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define _1 first
#define _2 second
#define pb push_back
#define mod 1000000007
#define INF 105000000000

const int maxn = 1e5 + 10;



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

	string s; cin >> s;

	int sa;
	FOR(i,1,100)
	{
		sa = i * 2;
		if(s.substr(0,(s.length()-sa)/2) == s.substr((s.length()-sa)/2, (s.length() - sa) / 2))
		{
			
			cout <<s.length() - sa << endl;
			return 0;
		}

	}


	return 0;
	
}

Measured memory_bytes: 256
s=list(input())
t=list(input())
flag=0
if s==t:
    flag=1
for i in range(len(s)):
    s.insert(0,s[-1])
    s.pop(-1)
    if s==t:
        flag=1
if flag==1:
    print('Yes')
else:
    print('No')

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k,s) = get!(usize, usize, usize);
    if k == 0 {
        if s == 1_000_000_000 {
            for i in 0..n {
                print!("{} ", 1);
            }
            println!("");
        } else {
            for i in 0..n {
                print!("{} ", 1_000_000_000);
            }
            println!("");
        }
        return;
    }
    let l = n-k+1;
    let t = s/l;
    let mut m = s%l;
    if t == 0 {
        for i in 0..k {
            print!("{} ", s);
        }
        for i in 0..n-k {
            print!("{} ", (s+1)%1_000_000_000);
        }
        println!("");
        return;
    }
    let mut vec = Vec::new();
    for i in 0..l {
        if m > 0 {
            vec.push(t+1);
            m -= 1;
        } else {
            vec.push(t);
        }
    }
    for i in 0..n {
        print!("{} ", vec[i%l]);
    }
    println!("");
}


Measured memory_bytes: 9596
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from heapq import heappush, heappop
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    pq = []
    heappush(pq, -A[0])
    ans = 0
    for a in A[1:]:
        b = -heappop(pq)
        ans += b
        heappush(pq, -a)
        heappush(pq, -a)
    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] == 5 && a[1] == 5 && a[2] == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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


def calc_kitaiti(n):
    sum_n = 0
    if n % 2 == 0:
        temp = n / 2
        sum_n = (temp * n) + temp
    else:
        temp = (n - 1) / 2
        sum_n = (n * (temp + 1))

    return sum_n / n


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    kitaitis = [0]
    pre = 0
    for _a in a:
        pre += calc_kitaiti(_a)
        kitaitis.append(pre)

    result = 0
    for i in range(k, n + 1):
        start = i - k
        result = max(result, kitaitis[i] - kitaitis[start])

    return result


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 25604
// Amsal toro ma ba cheshm migaiim
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long int
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
using namespace std;
//const int inf = -1e6;
const int minf = 1e9;
const int MAXN = 1e5+10;
//const int MAXM = 105;
int a[MAXN];
int dp[MAXN];
//int Primes[10]={2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n , k;
    cin >> n >> k;
   
     vector<int> dp(n, minf);
    // امروز اصن روز خوبی نبود :)))))))))))))))))
    for (int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
    }
    
    dp[0] = 0;
   
    
    for(int i = 0 ; i < n ; i++)
    {
        
        for(int j = i + 1 ; j <= i + k ; j++)
        {
            if(j < n)
            {
                dp[j] = min(dp[j] , dp[i] + abs(a[j] - a[i]));
            }
        }
    }
    
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 4024
import cmath
EPS = 1e-6

x, y, r = map(int, input().split())
c1 = (complex(x, y), r)
x, y, r = map(int, input().split())
c2 = (complex(x, y), r)

if abs(abs(c1[0]-c2[0]) - (c1[1]+c2[1])) <= EPS:
	print(3)
elif abs(max(c1[1], c2[1]) - min(c1[1], c2[1]) - abs(c1[0]-c2[0])) <= EPS:
	print(1)
elif abs(c1[0]-c2[0]) > c1[1]+c2[1]:
	print(4)
elif max(c1[1], c2[1]) - min(c1[1], c2[1]) > abs(c1[0]-c2[0]):
	print(0)
else:
	print(2)


Measured memory_bytes: 5700
#include<stdio.h>

#define MAX 100000

int parent(int);
int left(int);
int right(int);

int main(){

  int i,n;
  int arr[MAX+1];

  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&arr[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,arr[i]);
    if(parent(i)>=1)printf("parent key = %d, ",arr[parent(i)]);
    if(left(i)<=n)printf("left key = %d, ",arr[left(i)]);
    if(right(i)<=n)printf("right key = %d, ",arr[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent(int i){
  
  return i/2;
}

int left(int i){
  
  return 2*i;
}

int right(int i){
  
  return 2*i+1;
}

Measured memory_bytes: 608
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    double i,n,p,ans=0;
    scanf("%lf %lf",&n,&p);
    if(n==1)ans=p;
    else if(n>=40 || n>=p)ans=1;
    else if(n==2){
        for(i=1; i<=1000000; i++){
            if(fmod(p,pow(i,2))==0)ans=i;
        }
    }
    else if(n==3){
        for(i=1; i<=10000; i++){
            if(fmod(p,pow(i,3))==0)ans=i;
        }
    }
    else for(i=1; i<=1000; i++){
        if(fmod(p,pow(i,n))==0)ans=i;
    }
    printf("%.0lf",ans);
    return 0;
}

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

int main(){
  int n,m,c;
  cin >>n >> m >> c;
  VI b(m);
  VVI a(n,VI(m));
  rep(i,m) cin >>b.at(i);
  rep(i,n){
    rep(j,m) cin >>a.at(i).at(j);
  }
  int sum=0;
  int ans=0;
    rep(i,n){
		rep(j,m){
          sum+=(b.at(j)*a.at(i).at(j));
        }
    if(sum+c>0) ans++;
      sum=0;
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

def main():
    N = int(input())
    robots = []
    for _ in range(N):
        x,l = [int(x) for x in input().split()]
        robots.append((x-l, x+l))

    # print(sorted(robots.items(), key=lambda x:x[1]))
    cnt = 0
    t = -float('inf')
    for start,end in sorted(robots, key=lambda x:x[1]):
        # print(t,start)
        if t <= start:
            # print('append')
            cnt += 1
            t = end
    print(cnt)
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 59992
#include <stdio.h>

int H, W;
char G[1004][1004];
int x[1004][1004];

int numPaths(int i, int j) {
	if (i >= H || j >= W || G[i][j] == '#')
		return 0;
	if (i == H - 1 && j == W - 1)
		return 1;
	if (x[i][j] != -1)
		return x[i][j];
	x[i][j] = (numPaths(i + 1, j) + numPaths(i, j + 1)) % 1000000007;
	return x[i][j];
}

int main()
{
	scanf("%d %d", &H, &W);
	char temp;
	for (int i = 0; i < H; i++) {
		scanf("%c", &temp);
		for (int j = 0; j < W; j++) {
			scanf("%c", &G[i][j]);
			x[i][j] = -1;
		}
	}
	printf("%d", numPaths(0, 0));
}

Measured memory_bytes: 5120
/*
[abc141] E - Who Says a Pun?
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 5e3;

void z_algorithm(const string &s, vector<int> &ret) {
    int len = s.size();
    ret = vector<int>(len);
    ret[0] = len;
    int i = 1, j = 0;
    while (i < len) {
        while (i + j < len && s[j] == s[i + j]) {
            j++;
        }
        ret[i] = j;
        if (j == 0) {
            i++;
            continue;
        }
        int k;
        for (k = 1; i + k < len && k + ret[k] < j; k++) {
            ret[i + k] = ret[k];
        }
        i += k;
        j -= k;
    }
}

int N;
string S;

ll solve() {
    int ans = 0;
    for (int i = 0; i < N; i++) {
        vector<int> z;
        z_algorithm(S.substr(i), z);
        for (int i = 1; i < (int)z.size(); i++) {
            ans = max(ans, min(z[i], i));
        }
    }

    return ans;
}

int main() {
    cin >> N;
    cin >> S;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//UG 02 53 20 020
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);

if (a+b>=a-b&&a+b>=a*b)
    printf("%d",a+b);

else if(a+b>=a-b&&a+b>=a*b)
    printf("%d",a+b);

else if(a-b>=a+b&&a-b>=a*b)
    printf("%d",a-b);

else if(a*b>=a+b&&a*b>=a-b)
    printf("%d",a*b);

return 0;

}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

int n;
ll a[20][20], dp[(1 << 17) + 5];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	for(int j = 0 ; j < n ; ++j){
		cin >> a[i][j];
	}
}
for(int i = 1 ; i < (1 << n) ; ++i){
	for(int j = 0 ; j < n ; ++j){
		for(int v = 0 ; v < j ; ++v){
			if(((i >> j) & 1) && ((i >> v) & 1)){
				dp[i] += a[j][v];
			}
		}
	}
	for(int j = i ; j > 0 ; j = (j - 1) & i){
		dp[i] = max(dp[i], dp[j] + dp[i ^ j]);
	}
}
cout << dp[(1 << n) - 1] << endl;

return 0;
}



Measured memory_bytes: 768
#include<stdio.h>

typedef struct{
	int a;
	int b;
}SET;

/* ????????????????????£?¨? */
int count_digits(int value);

/* main??¢??° */
int main(void){
	SET set[200];
	int set_cnt, digits;
	int i;

	for(set_cnt = 0;set_cnt < 200;set_cnt++)
		if(scanf("%d %d", &(set[set_cnt].a), &(set[set_cnt].b)) == EOF)break;

	for(i = 0;i < set_cnt;i++){
		digits = count_digits(set[i].a + set[i].b);
		printf("%d\n", digits);
	}

	return 0;
}

/* ?????°?????°????????¢??° */
int count_digits(int value){
	int digits, power = 1;

	for(digits = 0;power <= value;digits++)
		power *= 10;

	return digits;
}

Measured memory_bytes: 1796