akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<long> res = new List<long>();
            res = (Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToList());
            Console.WriteLine(string.Format("{0} {1} {2}", res.Min(), res.Max(), res.Sum()));
        }
    }
}


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

int main() {
  cout << setprecision(20);
  int a, b; 
  cin >> a >> b;
  if ((a + b)%2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (a+b)/2 << endl; 
  }
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[input() for _ in range(h)]
ans=[['' for i in range(w)] for j in range(h)]
for i,l in enumerate(s):
    for j,c in enumerate(l):
        if c=='#':
            ans[i][j]='#'
        else:
            cnt = 0
            if i!=0:
                cnt += s[i-1][j]=='#'
            if j!=0:
                cnt += s[i][j-1]=='#'
            if i!=h-1:
                cnt += s[i+1][j]=='#'
            if j!=w-1:
                cnt += s[i][j+1]=='#'
            if i!=0 and j!=0:
                cnt += s[i-1][j-1]=='#'
            if i!=0 and j!=w-1:
                cnt += s[i-1][j+1]=='#'
            if i!=h-1 and j!=0:
                cnt += s[i+1][j-1]=='#'
            if i!=h-1 and j!=w-1:
                cnt += s[i+1][j+1]=='#'
            ans[i][j]=str(cnt)
for l in ans:
    print(''.join(l))


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 305;
const int mod = 1000000007;

ll f[maxn][maxn][maxn];
int a[maxn];

void pd(ll&ret,ll val){
  if(ret==-1||ret>val)ret=val;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>a[i];
  memset(f,-1,sizeof(f));
  f[0][0][0] = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<=i;j++)
      for(int k=0;k<=m;k++){
        if(f[i][j][k]==-1)continue;
        if(a[i+1]<=a[j]){
          pd(f[i+1][i+1][k],f[i][j][k]);
        } else {
          pd(f[i+1][i+1][k],f[i][j][k]+(a[i+1]-a[j]));
        }
        if(k==m)continue;
        pd(f[i+1][j][k+1],f[i][j][k]);
      }
  ll ret = -1;
  for(int i=0;i<=n;i++)
    for(int j=0;j<=m;j++)
      if(f[n][i][j]!=-1)pd(ret,f[n][i][j]);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 221952
# AOJ 0117 A reward for a Carpenter
# Python3 2018.6.21 bal4u

INF = 0x7fffffff

import heapq
def dijkstra(V, to, start, goal):
	dist = [INF]*V
	Q = []
	dist[start] = 0
	heapq.heappush(Q, (0, start))
	while len(Q):
		t, s = heapq.heappop(Q)
		if s == goal: break
		if dist[s] < t: continue
		for i in to[s]:
			e, cost = i
			nt = t + cost
			if dist[e] > nt:
				dist[e] = nt
				heapq.heappush(Q, (nt, e))
	return dist[goal]

n = int(input())+1
to = [[] for i in range(n)]
for i in range(int(input())):
	a, b, c, d = list(map(int, input().split(',')))
	to[a].append((b, c))
	to[b].append((a, d))
s, g, V, P = list(map(int, input().split(',')))
if s == g: print(V-P)
else: print(V-P - dijkstra(n, to, s, g) - dijkstra(n, to, g, s))


Measured memory_bytes: 5664
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long k = sc.nextLong();
      int[] arr = new int[n+1];
      for(int i = 1; i <= n; i++)
        arr[i] = sc.nextInt();

      int fast = 1;
      int slow = 1;
      long moves = 0;
      while(true) {
        fast = arr[arr[fast]];
        slow = arr[slow];
        moves++;
        if(fast == slow) break;
      }

      fast = 1;
      while(fast != slow && k > 0) {
        fast = arr[fast];
        slow = arr[slow];
        k--;
      }

      if(k > 0) {
        int res = fast;
        long step = k % moves;
        for(long i = 0; i < step; i++)
          res = arr[res];
        System.out.println(res);
      } else {
        System.out.println(fast);
      }
  }
}


Measured memory_bytes: 50236
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,ans;
    scanf("%d",&n);
    if(n<10)
    {
        ans=n;
    }
    if(n>=10&&n<100)
    {
        ans=9;
    }
    if(n>=100&&n<1000)
    {
        ans=9+n-100+1;
    }
    if(n>=1000&&n<10000)
    {
        ans=909;
    }
    if(n>=10000&&n<100000)
    {
        ans=909+n-10000+1;
    }
    if(n>=100000)
    {
        ans=90909;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

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

int main(){
    int x;
    cin >> x;
    if(360%x==0){
        cout << 360/x << endl;
    }
    else{
        cout << lcm(360,x)/x << endl;
    }

    return 0;
}


Measured memory_bytes: 3540
n = int(input())
num_list = list(map(int, input().split()))
a = int(num_list[0])
p = 0

for i in range(n):
  if num_list[i] < a:
    p = p + (a - num_list[i])
  elif num_list[i] > a:
    a = num_list[i]
  
print(p)

Measured memory_bytes: 32248
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    long long n, k, d;
    cin >> n >> k;
    vector<char> used(n + 1, false);
    for(int i = 0; i < k; ++i){
        cin >> d;
        for(int j = 0; j < d; ++j){
            long long s;
            cin >> s;
            used[s] = true;
        }
    }
    long long c = 0;
    for(int i = 1; i <= n; ++i){
        if(!used[i]) c++;
    }
    cout << c;
}

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

int main() {
    int K, S;
    cin >> K >> S;
    int counter = 0;
    for (int X=0; X<=K&X<=S; X++) {
        for (int Y=0; Y<=K&Y<=S-X; Y++) {
            if (S-X-Y <= K) counter++;
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>

typedef long long ll;
using namespace std;

struct Point{
    int id,x,y;

    void assign(int id_,int x_,int y_){
      id=id_,x=x_,y=y_;
    }

    bool operator <(const Point &p) const{
      return id<p.id;
    }
  };

  bool compX(const Point &a,const Point &b){
    return a.x<b.x;
  }
  bool compY(const Point &a,const Point &b){
    return a.y<b.y;
  }

struct Node{
  int l,r,index;

  Node(){
    l=r=-1;
  }
};

struct KDTree{
  vector<Node> node;
  vector<Point> point;

  int n,np;

  void init(int n_){
    n=n_;
    np=0;
    node.clear();
    point.clear();
    node.resize(n*2);
    point.resize(n);
  }

  int makeTree(int l,int r,int depth){
    if(l>=r)return -1;
    int v=np++;
    int m=(l+r)/2;

    if(depth%2==0){
      sort(point.begin()+l,point.begin()+r,compX);
    }
    else{
      sort(point.begin()+l,point.begin()+r,compY);
    }

    node[v].index=m;
    node[v].l=makeTree(l,m,depth+1);
    node[v].r=makeTree(m+1,r,depth+1);

    return v;
  }
  
  void find(int v,int sx,int sy,int tx,int ty,int depth,vector<int> *ans){
    int x=point[node[v].index].x;
    int y=point[node[v].index].y;

    if(sx<=x&&x<=tx&&sy<=y&&y<=ty){
      ans->push_back(point[node[v].index].id);
    }

    if(depth%2==0){
      if(node[v].l!=-1&&sx<=x)find(node[v].l,sx,sy,tx,ty,depth+1,ans);
      if(node[v].r!=-1&&x<=tx)find(node[v].r,sx,sy,tx,ty,depth+1,ans);
    }
    else{
      if(node[v].l!=-1&&sy<=y)find(node[v].l,sx,sy,tx,ty,depth+1,ans);
      if(node[v].r!=-1&&y<=ty)find(node[v].r,sx,sy,tx,ty,depth+1,ans);
    }
  }
};

int main(void){
  int n,q,i,j;
  int x,y,sx,sy,tx,ty;

  cin>>n;

  KDTree tree;
  tree.init(n);

  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    tree.point[i].assign(i,x,y);
  }

  tree.makeTree(0,n,0);

  vector<int> ans;

  cin>>q;
  for(i=0;i<q;i++){
    ans.clear();
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    tree.find(0,sx,sy,tx,ty,0,&ans);
    sort(ans.begin(),ans.end());

    for(j=0;j<ans.size();j++){
      printf("%d\n",ans[j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 19916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string ans("APPROVED");
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i) % 2 == 0){
      if(a.at(i) % 3 != 0){
        if(a.at(i) % 5 != 0){
       	 	ans = "DENIED";
    	    break;
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	double W,H,x,y,ANS;
	cin >> W >> H >> x >> y;
	ANS=W*H/2;

	if(x==W/2&&y==H/2)
	{
		cout << ANS << " 1" << endl;
	}
	else
	{
		cout << ANS << " 0" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
	
	int n;
	scanf("%d", &n);
	
	for (int i=1; i<10; i++){
		if (n % i == 0 && n / i < 10){
			printf("Yes");
			
			return 0;
		}
	}
	printf("No");
	
	return 0;
}

Measured memory_bytes: 1696
#include<stdio.h>
#include<math.h>
#define N 10000
int isPrime(int);
 
int main(){
  int x,i,j,u,c=0,count=0;
  int s[N];
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&s[i]);
  }
  for(i=0;i<x;i++){
    u = isPrime( s[i] );
    if(u == 1) count++;
  }
 
  printf("%d\n",count);
   
  return 0;
}
 
int isPrime(int x){
  int i;
 
  if(x==2) return 1;
  if( x<2 || x%2==0) return 0;
 
  i = 3;
  while(i<= sqrt(x) ){
    if( x % i ==0 ) return 0;
    i = i + 2;
  }

  return 1;
}
  



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define t first
#define s second.first 
#define d second.second

int main(){
  vector <pair<int ,pair<int ,int> > > a;
  while(1){
  int n,m;
  int b[20001]={};
  b[1]=1;
  cin>>n>>m;
  if(n==0 && m==0)break;
  a.resize(m);
  for(int i=0;i<m;i++)
    cin>>a[i].t>>a[i].s>>a[i].d;

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

  int count=1;
  for(int i=0;i<m;i++)
    if(b[a[i].s]==1 && b[a[i].d]==0){
	b[a[i].d]=1;
	count++;
    }
  cout<<count<<endl;
  }

  return 0;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a[200005],max1=0,max2=0;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[i];
    if(a[i]>max1){
      max2=max1;
      max1=a[i];
    }else if(a[i]>max2 && max1>=a[i]){
      max2=a[i];
    }
  }

  for(int i=0; i<n; i++){
    if(a[i]==max1){
      cout<<max2<<'\n';
    }else{
      cout<<max1<<'\n';
    }
  }
  return 0;
}
      


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

using namespace std;


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


    long long int A[1112];

    for (int i=0;i<1112;i++)
    {
        A[i] = i*i*i;
    }

    int T;
    cin >> T;
    while (T!=0)
    {

        long long int Z = A[T];
        long long int maxdif = Z;

        for (int i=1;i<T;i++)
        {
            long long int X = A[i];
            long long int Y = cbrt(Z-X);
            Y = A[Y];

            long long int ans = Z-X-Y;
            maxdif = min(maxdif,ans);
        }

            cout << maxdif << "\n";

            cin >> T;


    }

    return 0;
}

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

using namespace std;

typedef pair<int, int> PII;
const int MAXN = 1000000 + 10;
int X, Y, n;
int a[MAXN];
PII p[MAXN][2];

bool onborder(PII a) {
    return (a.first == 0 || a.first == X || a.second == 0 || a.second == Y);
}

int numonborder(PII a) {
    if (a.second == 0) {
        return a.first;
    }
    if (a.first == X) {
        return X + a.second;
    }
    if (a.second == Y) {
        return X + Y + (X - a.first);
    }
    if (a.first == 0) {
        return 2 * X + Y + (Y - a.second);
    }
    return -1;
}
vector<PII> v;

int cnt[MAXN];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> X >> Y >> n;    
    for (int i = 0; i < n; i++) {
        cin >> p[i][0].first >> p[i][0].second >> p[i][1].first >> p[i][1].second;
        int x, y;
        x = numonborder(p[i][0]);
        y = numonborder(p[i][1]);
        if (x != -1 && y != -1) {
            v.push_back({x, i});
            v.push_back({y, i});
            
        }
    }

    sort(begin(v), end(v));

    bool dupa = false;
    int bad = 0;
    int q = 0;
    vector<int> lol;
    for (auto y : v) {
        auto x = y.second;
        //cerr << x << "\n";
        cnt[x]++;
        if (cnt[x] == 2) {
            if (lol.back() != x) { dupa = true; break; }
            lol.pop_back();

        } else if (cnt[x] == 1) {
            lol.push_back(x);
        }

    }

    if (dupa) cout << "NO\n";
    else cout << "YES\n";

    return 0;
}


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

struct P
{
    //int x,y;
    int o[5];
    /*bool operator<(const P &a)const{
              return x>a.x;
    }*/

};

vector<P> v;
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[110];
int l[10];
int j[10];
int e;
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007;
long long z;
double pi=3.14159265;
P jk;
stack<int> s;

//set<int> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

string r;
//char r[133];
//deque<int> de;
bool as(P a,P b)
{
    for(int t=0;t<5;t++)
        if(a.o[t]!=b.o[t]) return a.o[t]<b.o[t];
    return 0;
}
int main()
{
    scanf("%d\n",&a);
    for(int t=1;t<=2*a;o[t]-='a',t++)
        scanf("%c",&o[t]);
    for(i=0;i<(1<<a);i++)
    {
        P u=jk;
        int h=0;
        for(int p=i,t=2*a;t>a;t--,p/=2)
            if(p%2)
            {
                u.o[h/5]*=60;
                u.o[h/5]+=o[t];
                h++;
            }
        for(int p=i,t=2*a;t>a;t--,p/=2)
            if(p%2==0)
            {
                u.o[h/5]*=60;
                u.o[h/5]+=o[t]+30;
                h++;
            }
        //for(int t=0;t<5;t++)
        //    printf("%d ",u.o[t]);
        v.push_back(u);
    }
    v.push_back(jk);
    e=2100000000;
    v.push_back({e,e,e,e});
    sort(v.begin(),v.end(),as);
    for(int i=0;i<(1<<a);i++)
    {
        P u=jk;
        int h=0;
        for(int p=i,t=1;t<=a;t++,p/=2)
            if(p%2)
            {
                u.o[h/5]*=60;
                u.o[h/5]+=o[t];
                h++;
            }
        for(int p=i,t=1;t<=a;t++,p/=2)
            if(p%2==0)
            {
                u.o[h/5]*=60;
                u.o[h/5]+=o[t]+30;
                h++;
            }
            //for(int t=0;t<5;t++)
           // printf("%d ",u.o[t]);
        int n=0,m=v.size()-1,c=0,d=v.size()-1;
        for(;n<m;)
        {
            int h=(n+m)/2+1;
            for(int t=0;t<5;t++)
                if(u.o[t]!=v[h].o[t])
            {
                if(u.o[t]<v[h].o[t])
                    m=h-1;
                else n=h;
                goto qwe;
            }
            m=h-1;
            qwe:;
        }

        for(;c<d;)
        {
            int h=(c+d)/2;
            for(int t=0;t<5;t++)
                if(u.o[t]!=v[h].o[t])
            {
                if(u.o[t]<v[h].o[t])
                    d=h;
                else c=h+1;
                goto qwer;
            }
            c=h+1;
            qwer:;
        }
        x+=c-n-1;
        //printf("%d %lld %d %d\n",i,x,c,n);
    }
    printf("%lld",x);
}



Measured memory_bytes: 12524
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int n, a[MX], m;
ll x[MX], cum[MX];
ll k;

void sim(int z) {
    x[z] = x[z-1]+x[z+1]-x[z];
}

void input() {
    // freopen("A.txt","r",stdin);
    // freopen("C.txt","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    FOR(i,1,n+1) cin >> x[i];
    cin >> m >> k;
    FOR(i,1,m+1) cin >> a[i];
}

void brute() {
    F0R(i,k) FOR(j,1,n+1) sim(a[j]);
    FOR(i,1,n+1) cout << x[i] << " ";
}

void ad(int l, int r, ll x) {
    cum[l] += x, cum[r+1] -= x;
}

int locLeft[60][MX], locRight[60][MX];

int getLocLeft(int x, ll y) {
    F0Rd(i,60) if (y&(1LL<<i)) x = locLeft[i][x];
    return x;
}

int getLocRight(int x, ll y) {
    F0Rd(i,60) if (y&(1LL<<i)) x = locRight[i][x];
    return x;
}

int tmpLeft[MX], tmpRight[MX];

int main() {
    input();
    FOR(i,1,n+1) tmpLeft[i] = tmpRight[i] = i;
    FOR(i,1,m+1) {
        swap(tmpRight[a[i]-1],tmpRight[a[i]]);
        swap(tmpLeft[a[i]+1],tmpLeft[a[i]]);
    }
    FOR(i,1,n+1) {
        locLeft[0][tmpLeft[i]] = i;
        locRight[0][tmpRight[i]] = i;
    }
    FOR(j,1,60) FOR(i,1,n+1) {
        locLeft[j][i] = locLeft[j-1][locLeft[j-1][i]];
        locRight[j][i] = locRight[j-1][locRight[j-1][i]];
    }
    FOR(i,1,n+1) {
        int a = getLocLeft(i,k), b = getLocRight(i,k);
        // cout << a << " " << b << "\n";
        if (a <= b) ad(a,b,x[i]);
        else ad(b+1,a-1,-x[i]);
    }
    
    FOR(i,1,n+1) {
        cum[i] += cum[i-1];
        cout << fixed << setprecision(1) << (ld)cum[i] << "\n";
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 51072
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll cnt[200];
int main(){
	ll n;
	cin>>n;
	vector<ll> x,y;
	for(int i=0;i<n;i++){
		ll tx,ty;
		cin>>tx>>ty;
		x.pb(tx);
		y.pb(ty);
	}
	long double r = 100000.0*mod;
	long double pi = 2.0 * asin(1.0);
	ll tur = 2000000;
	for(int i=0;i<tur;i++){
		long double rx = r * cos( 2.0 * pi * (1.0*i) / (1.0*tur) );
		long double ry = r * sin( 2.0 * pi * (1.0*i) / (1.0*tur) );
		long double mi = r * r * 2;
		ll good = -1;
		for(int j=0;j<n;j++){
			long double dis = (rx-x[j]*1.0)*(rx-x[j]*1.0)+(ry-y[j]*1.0)*(ry-y[j]*1.0);
			if(dis < mi){
				mi = dis;
				good = j;
			}
		}
		cnt[good]++;
	}
	for(int i=0;i<n;i++){
		long double ans = cnt[i] * 1.0 / tur;
		cout<<std::setprecision(20)<<ans<<endl;
	}
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, a, b;
  cin >> n >> a >> b;
  
  int x = 0, y = 0, z = 0;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    if (p <= a) x++;
    else if (p <= b) y++;
    else z++;
  }
  
  cout << min({x, y, z}) << '\n';
}

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

int main(){
    string o,e; cin >> o >> e;
    for (int i = 1;i<=(o.size() + e.size());i++){
        if (i % 2 == 0){
            cout << e[(i-1)/2];
        } else {
            cout << o[(i-1)/2];
        }
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int total = 0;
        for(int i = 0; i < n; i++){
            t[i] = sc.nextInt();
            total += t[i];
        }
        int m = sc.nextInt();
        for(int i = 0; i < m; i++){
            int k = sc.nextInt()-1;
            System.out.println(total-t[k]+sc.nextInt());
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int mod  = 100003;
const int maxn = 1e5+10;

ll val[105],v[105],dp[100025];
int main()
{
	int n,V;
	ll ans = 0;
	scanf("%d%d",&n,&V);
    for(int i = 1;i<=n;++i)
		scanf("%lld%lld",&v[i],&val[i]);
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i = 1;i<=n;++i)
    {
        for(int j = 100000;j>=val[i];j--)
            dp[j] = min(dp[j],dp[j-val[i]]+v[i]);
    }
    for(int i = 1;i<=1e5;++i)
    	if(dp[i]<=V)
    		ans = max(ans,1ll*i);
    printf("%lld\n",ans);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	vvll v(n,vll(n));
	rep(i,n/2) (n%2?v[i][n-2-i]:v[i][n-1-i])=1;
	ll cnt=0;
	rep(i,n-1){
		for(ll j=i+1;j<n;j++){
			if(!v[i][j]) cnt++;
		}
	}
	cout << cnt << endl;
	rep(i,n-1){
		for(ll j=i+1;j<n;j++){
			if(!v[i][j]) cout << i+1 << " " << j+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int main() {
	string s;
    cin >> s;
    int D[4];
    rep(i, 4) D[i] = 0;
    rep(i, s.length()){
        if(s[i] == 'N') D[0] = 1;
        if(s[i] == 'S') D[1] = 1;
        if(s[i] == 'E') D[2] = 1;
        if(s[i] == 'W') D[3] = 1;
    }

    int ret = ~((D[0]^D[1]) | (D[2]^D[3])) & 1;
    cout << (ret == 1? "Yes" : "No") << endl;

}

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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int N;
int x,y;
int a[111],b[111],c[111],d[111];

int dp[110][310][910];

signed main(){
    cin>>N>>x>>y;
    rep(i,N)cin>>a[i]>>b[i]>>c[i]>>d[i];

    fill_n(**dp,110*310*910,-INF);
    dp[0][x][300+y]=0;
    rep(i,N){
        rep(j,301){
            rep(k,901){
                if(dp[i][j][k]==-INF)continue;
                chmax(dp[i+1][j][k],dp[i][j][k]);
                if(j-a[i]>=0)chmax(dp[i+1][j-a[i]][k+b[i]],dp[i+1][j][k]);
                chmax(dp[i+1][j][k-c[i]],dp[i][j][k]+d[i]);
            }
        }
    }

    int ma=0;
    rep(i,x+1)reps(j,300,901)chmax(ma,dp[N][i][j]);
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 245548
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

/////////////////////////////////////////////////////////////////////////////////////////
int n,q;
vector<vector<int>> g(1e6);
int seen[300000];
vector<int> counter(300000);

void dfs(int P,int pre){
    
    counter[P] += counter[pre];

    for (auto next : g[P]){
        if (next != pre) dfs(next,P);
    }
}

int main(){
    cin >> n >> q;
    vector<int> p(q);

    for (int i = 1;i < n;i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 0;i < q;i++){
        int p,x;
        cin >> p >> x;
        counter[p] += x;
    }

    dfs(1,0);

    for (int i = 1;i <= n;i++){
        cout << counter[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 43392
#include "bits/stdc++.h"
using namespace std;
const int N = 5e3 + 3;
const long long inf = 1e15 + 15;
int n;
pair < int , int > arr[N];
long long dp[2][N];
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d %d" , &arr[i].first , &arr[i].second);
		arr[i].first += arr[i].second;
	}
	sort(arr + 1 , arr + 1 + n);
	for(int i = 0 ; i <= n ; ++i){
		dp[0][i] = inf;
		dp[1][i] = inf;
	}
	dp[0][0] = 0;
	dp[1][0] = 0;
	for(int i = 1 ; i <= n ; ++i){
		int h = arr[i].first - arr[i].second;
		int p = arr[i].second;
		for(int j = 1 ; j <= i ; ++j){
			dp[i & 1][j] = dp[!(i & 1)][j];
			if(dp[!(i & 1)][j - 1] <= h){
				dp[i & 1][j] = min(dp[i & 1][j] , dp[!(i & 1)][j - 1] + p);
			}
		}
	}
	for(int i = n ; i >= 0 ; --i){
		if(dp[n & 1][i] < inf){
			printf("%d\n" , i);
			return 0;
		}
	}
}

Measured memory_bytes: 384
# coding: utf-8
A, B, K = (int(n) for n in input().split())

if A <= K:
  K = K - A
  A = 0
else:
  A = A - K
  print(A, B)
  exit()
if B <= K:
  K = K - B
  B = 0
else:
  B = B - K
  print(A, B)
  exit()
print(A, B)


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

#define ll long long
#define all(x) (x).begin(),(x).end()
#define dlog(x) cout<<#x<<'='<<x<<'\n'

using namespace::std;

int main(){
      ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
      int a,b; cin>>a>>b;
      cout<<min(string(a,b+'0'),string(b,a+'0'));
      return 0;
}

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

int main(){
	string st;

	cin >>st;
	if(st[0]==st[1]&&st[0]==st[2])cout<<"Yes"<<endl;
	else if(st[3]==st[1]&&st[3]==st[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<string > vecstr;
int main()
{
  ll a,  b, x;
  cin >> a >> b >> x;
  ll ans = b/x - a/x + (a % x == 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    ll n,k;
    cin >> n >> k;
    ll a = n % k;
    ll b = a - k;
    if(a < abs(b)){
        cout << a;
    }else{
        cout << abs(b);
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define sgn(v) (abs((v))<eps?0:((v)<0?-1:1))
#define sqr(v) ((v)*(v))
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define debug 0
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double,int> PDI;
typedef pair<double,double> PDD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
const double eps=1e-9;
const double pi=acos(-1);
const int maxn=3000;
vector<PDD> it;
PDD tp[maxn];
double ag[4];
bool cmpSE(PDD p,PDD q)
{
	if(sgn(p.SE-q.SE))return p.SE<q.SE;
	else return p.FI<q.FI;
}
bool In(double v,double l,double r)
{
	for(int k=-3;k<=3;++k)
		if((sgn(l-v-k*2*pi)<=0&&sgn(v+k*2*pi-r)<=0))return true;
	return false;
}
int main()
{
	//cout <<pi/4*3<<endl;
	int n,i,j,con;
	int x1,y1,x2,y2,tk;
	double l,r,nr;
	scanf("%d",&n);
	for(i=0;i<n;++i)
	{
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		ag[0]=atan2(y1,x1);ag[1]=atan2(y1,x2);
		ag[2]=atan2(y2,x1);ag[3]=atan2(y2,x2);
		sort(ag,ag+4);
		l=ag[0],r=ag[3];
		//cout <<ag[0]<<" "<<ag[1]<<" "<<ag[2]<<" "<<ag[3]<<endl;cout <<l<<" "<<r<<endl;
		if(sgn(r-l-pi)>0)
		{
			for(j=0;j<4;++j)if(sgn(ag[j])<0)ag[j]+=2*pi;
			sort(ag,ag+4);
			l=ag[0],r=ag[3];
		}
		//cout <<l<<" "<<r<<endl;
		if(sgn(l-r)>0)while(1);
		it.PB(MP(l,r));
	}
	sort(it.begin(),it.end(),cmpSE);
	//for(i=0;i<it.size();++i)cout <<it[i].FI<<" "<<it[i].SE<<endl;
	int ans=n;
	for(i=0;i<it.size();++i)
	{
		nr=it[i].FI;
		tk=0;
		con=1;
		for(j=0;j<i;++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp[tk++]=MP(it[j].FI+2*pi,it[j].SE+2*pi);
		}
		for(j=i+1;j<it.size();++j)
		{
			if(In(nr,it[j].FI,it[j].SE))continue;
			tp[tk++]=(it[j]);
		}
		//cout <<"This is l:"<<nr<<" "<<tp.size()<<endl;for(j=0;j<tp.size();++j)cout <<tp[j].FI<<" "<<tp[j].SE<<endl;
		for(j=0;j<tk;++j)
		{
			if(j==0||!(In(nr,tp[j].FI,tp[j].SE)))
				nr=tp[j].SE,++con;
		}
		ans=min(ans,con);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    string S1, S2;
    cin >> S1 >> S2;
    if (S1[0] == S2[2] && S1[2] == S2[0] && S1[1] == S2[1]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
const int N=200005,P=998244353;
int n,f[N],p[N],a;char c[N];
inline int ck(int x)
{
	for(int i=1,j=1,w=0;i<=n;++i,j==x?(j=1,w^=1):++j)
		if(c[i]<(c[j]^w))return 0;
		else if(c[i]>(c[j]^w))return 1;
	return 1;
}
int main()
{
	scanf("%d%s",&n,c+1);
	p[0]=1;for(int i=1;i<=n;++i)p[i]=p[i-1]*2%P;
	for(int d=1;d<=n;++d)if(!(n%d)&&n/d&1)
	{
		for(int i=1;i<=d;++i)
		if(c[i]=='1')(f[d]+=p[d-i])%=P;
		(f[d]+=ck(d))%=P;
		for(int g=1;g<d;++g)if(!(d%g)&&n/g&1)
			(f[d]+=P-f[g])%=P;
		a=(2ll*d*f[d]+a)%P;
	}
	return printf("%d",a),0;
}

Measured memory_bytes: 2700
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}
	cost := make([]int, N+1)
	cost[0] = 0
	cost[1] = abs(h[1] - h[0])
	for i := 0; i < N-2; i++ {
		cost[i+2] = min(cost[i]+abs(h[i+2]-h[i]), cost[i+1]+abs(h[i+2]-h[i+1]))
	}
	fmt.Println(cost[N-1])

}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a;
    cin >> a;
    cout << (a + a * a + a * a * a) << endl;
    
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        long gcd = -1;
        long maxValue = 0;
        for(int i = 0; i < n; ++i) {
            int num = sc.nextInt();
            maxValue = Math.max(maxValue, num);
            gcd = (gcd < 0) ? num : findGCD(gcd, num);
        }

        if(k % gcd == 0 && k <= maxValue) System.out.println("POSSIBLE");
        else System.out.println("IMPOSSIBLE");
    }

    static long findGCD(long a, long b) {
		if(a < b) return findGCD(b, a);
		if(b == 0) return a;
		return findGCD(b, a % b);
	}
}

Measured memory_bytes: 48140
//http://drken1215.hatenablog.com/entry/2018/07/18/214400
//を参考
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAX_V=1e3+5;
const int INF=1e9;
char board[35][35];
vector<vector<int> > graph;//整数の形に予め整備しておければ大分手間が省ける
typedef pair<int,int> pii;
typedef pair<pii,bool> state;
int dp[65][35][2];// x座標,y座標,右足or左足:0,1
int w,h;
int ans=INF;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
  std::fill( (T*)array,(T*)(array+N),val );
}

int main(void)
{
  while(cin >> w >> h && w)
    {
      ans=INF;
      vector<pii> starts;
      set<pii> goals;//goalについた時点で終わりなので,存在判定などがすぐにできるsetだと都合が良い
      graph.clear();
      graph.resize(h);
      for (int i = 0; i < h; ++i)
	{
	  for (int j = 0; j < w; ++j)
	    {
	      char c;
	      int time=0;
	      cin >> c;
	      if(c=='X') time=-1;
	      else if(c=='S') starts.push_back(pii(i,j)),time=0;
	      else if(c=='T') goals.insert(pii(i,j)),time=0;
	      else time=(int)(c-'0');
	      graph[i].push_back(time);
	    }
	}
      priority_queue<pair<int,state>,vector<pair<int,state> >,greater<pair<int,state> > > que;//(距離,状態)  状態:((y座標,x座標),今の足)
      Fill(dp,INF);
      for(auto p: starts)
	{
	  for(int foot=0;foot<2;foot++)
	    {
	      dp[p.first][p.second][foot]=0;
	      que.push(make_pair(0,state(p,foot) ) );
	    }
	}
      //startが多くても,全て左右の足で試してみる.
      while(!que.empty())
	{
	  auto now=que.top();que.pop();
	  int nowdist=now.first;//dpから持ってくる!　dp更新が起きた時だけqueに詰めるようにすれば計算量削減に繋がるようだ.
	  pii p=now.second.first;
	  int foot=now.second.second;
	  if(goals.count(p)) ans=min(ans,nowdist);//とにかく今の(y座標,x座標)が,どれかのゴールであれば答えを更新.
	  if(nowdist>dp[p.first][p.second][foot]) continue;
	  for (int i = 0; i < h; ++i)
	    {
	      for (int j = 0; j < w; ++j)
		{
		  //登り得る候補はh*w程度なので全て試してみる.(条件に合わせてより好みするのは少し難しそう)
		  if(foot==0 && j<=p.second) continue;//右足が左足より左
		  if(foot==1 && j>=p.second) continue;//左足が右足より右
		  if(abs(i-p.first)+abs(j-p.second)>3) continue; // | lx - rx | + | ly - ry | ≤ 3
		  if(graph[i][j]==-1) continue;
		  if(dp[i][j][1-foot]>nowdist+graph[i][j])//1-1=0↔1-0=1
		    {
		      dp[i][j][1-foot]=nowdist+graph[i][j];
		      que.push(make_pair(dp[i][j][1-foot],state(pii(i,j),1-foot)));
		    }
		}
	    }
	}
      if(ans==INF) cout << -1 << endl;
      else cout << ans << endl;
    }
  return 0;
 
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;
int N;
int a[102];

int main(void) {

	cin >> N;

	int tmp;

	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		a[i] = tmp;
	}

	int count = 0;
	int q = -1;

	for (int i = 2; i <= N; i++) {
		if (a[i - 1] == a[i]) { a[i] = q; q--; count++; }
	}

	cout << count << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*~-n
while sum(a)<k and d<9999:
 L=[1]*n;y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]*L[x]*L[i]==i+1:
    a[i]+=1;a[x]+=1;L[i]=L[x]=0;y=1
print([k//2,d*y-1][d*y<9999])

Measured memory_bytes: 53852
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const long long linf = 4523372036854775807;
const int iinf = 1500000000;
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	int from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
int fact(int i) {
	ll sum = 1;
	for (int j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
int h, w;
int c[10][10];
int a[200][200];
int b[10];
signed main() {
	cin >> h >> w;
	for (int i = 0; i < 10; i++) {
		b[i] = iinf;
		for (int j = 0; j < 10; j++) 
			cin >> c[i][j];
	}
	priority_queue<P, vector<P>, greater<P>>p;
	b[1] = 0;
	p.push(P{ 1,0 });
	while (!p.empty()) {
		P t = p.top(); p.pop();
		for (int i = 0; i < 10; i++) {
			if (b[i] > t.cost + c[i][t.pos]) {
				b[i] = t.cost + c[i][t.pos];
				p.push(P{ i,b[i] });
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] > -1)
				sum += b[a[i][j]];
		}
	}
	cout << sum << endl;
	getchar(); getchar();
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int flag = 0;
  if(s[0] == s[1]){
    if(s[0] != s[2] && s[2] == s[3]){
      flag = 1;
    }
  }
  else if(s[0] == s[2]){
    if(s[0] != s[1] && s[1] == s[3]){
      flag = 1;
    }
  }
  else if(s[0] == s[3]){
    if(s[0] != s[2] && s[1] == s[2]){
      flag = 1;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

signed main() {
    long long r, d, x;
    cin >> r >> d >> x;
    
    for ( int i = 0; i < 10 ;i++ ) {
        x = r * x - d;
        cout << x << endl;
    }
    return (0);
}

Measured memory_bytes: 3576
n = int(input())

def search(s="0"):
    if int(s) > n: return 0
    cnt = 0
    if "3" in s and "5" in s and "7" in s:
        cnt += 1
    cnt += search(s + "3")
    cnt += search(s + "5")
    cnt += search(s + "7")
    return cnt
print(search())


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

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

    int cnt = 1;
    int ans = 0;
    while (cnt < b) {
        ans++;
        cnt += a - 1;
    }

    cout << ans << endl;

    return 0;
}


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

int n, x, y;
vector<int> G[100000];
int P[100000];
int Q[100000];

void rec(int* a, int from, int prev, int dist) {
  a[from] = dist;
  for (int to : G[from]) {
    if (to == prev) continue;
    rec(a, to, from, dist + 1);
  }
}

int main() {
  cin >> n >> x >> y;
  --x; --y;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  rec(P, x, -1, 0);
  rec(Q, y, -1, 0);
  
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    if (P[i] >= Q[i]) continue;
    mx = max(mx, Q[i] - 1);
  }
  cout << mx << endl;
}

Measured memory_bytes: 11648
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	ll N;
	cin >> N;
	unordered_map<string, ll> mp;
	ll ans = 0;
	for (ll i = 0; i < N; i++)
	{
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		auto itr = mp.find(s);
		if (itr != mp.end())
		{
			ans += itr->second;
			itr->second++;
		}
		else
		{
			mp[s] = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

int main(){
    ll a;
    string s;
    cin >> a >> s;
    int cnt = 0;
    int b = 0;
    bool f = false;
    for(char c : s){
        if(c == '.'){
            f = true;
            continue;
        }
        if(f)   cnt++;
        b = b*10+(c-'0');
    }
    a *= b;
    while(cnt--)    a /= 10;
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	vi a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	sort(ALL(a)), sort(ALL(b));
	if(n & 1) {
		cout << b[n / 2] - a[n / 2] + 1 << endl;
	} else {
		cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
	}

}





Measured memory_bytes: 4780
#include<iostream>
using namespace std;
int main()
{
   int n,a=1000,x;
   cin>>n;
   if(n%a==0)
   {
       x=0;
       cout<<x<<endl;
   }
   else
    {
         x=a-(n%a);
         cout<<x<<endl;
   }
    return 0;


}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int K, A, B; cin >> K >> A >> B;
    bool isOK = false;
    for(int i=A; i<=B; i++){
        if(i % K == 0) isOK = true;
    }
    if(isOK) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[200];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a+n);
    int ans = 2000000;
    for(int i = a[0]; i <= a[n-1]; i++)
    {
        int num=0;
        for(int j = 0; j < n; j++)
        {
            num += abs(i-a[j])*abs(i-a[j]);
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
abc=[list(map(int, input().split())) for _ in range(n)]
dp=[0]*3

for a,b,c in abc:
    dp=[max(dp[1],dp[2])+a,max(dp[0],dp[2])+b,max(dp[0],dp[1])+c]
print(max(dp))

Measured memory_bytes: 30580
# 18-Character-Ring.py

# ????????°
# ???????????????????????°??¶???????????? s ???????????????????????????????¨????????????£?¶????????????????????????????????????§???
# ????????? p ??????????????????????????????????????°????????????????????????????????????

# Input
# ????????????????????? s ????????????????????????
# ????????????????????? p ????????????????????????

# Output
# p ??????????????´?????? Yes ??¨?????????????????´?????? No ??¨????????????????????????????????????

# Constraints
# 1???p????????????s????????????100
# ??????????????±?°???????????????????

# Sample Input 1
# vanceknowledgetoad
# advance
# Sample Output 1
# Yes

# Sample Input 2
# vanceknowledgetoad
# advanced
# Sample Output 2
# No

import re

pattern=[]

s=input()
p=input()

s= s+s

# for p2 in list(p):
# 	pattern.append(p2)
# 	pattern.append(".*")

# pattern = "".join(pattern)
# print(pattern)

matchOB = re.search(p, s)

if matchOB:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 7632
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}

int main(void){

    int n;
    cin>>n;

    int count = 0;
    long long int sum = 0;
    long long int min = pow(10,10);

    for(int i=0;i<n;i++){
        long long int a;
        cin>>a;
        if(abs(a) < min) min = abs(a);
        sum += abs(a);
        if(a<0) count++;
        //cout<<sum <<" ";
    }

    if(count%2==0) cout<<sum<<endl;
    else cout<<sum-2*min<<endl;
    
    return 0;

}

Measured memory_bytes: 256