akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nk[0];
            int k = nk[1];
            int[] v = ReadLine().Split(' ').Select(int.Parse).ToArray();

            int[] dp = new int[n];
            dp[0] = 0;
            for (int i = 1; i < n; i++)
            {
                int mintmp = int.MaxValue;
                for (int j = 1; j <= k; j++)
                {
                    if (i - j < 0) continue;
                    mintmp = Min(mintmp,Abs(v[i]-v[i-j])+dp[i-j]);
                }
                dp[i] = mintmp;
            }
            WriteLine(dp[n-1]);
        }
    }
}


Measured memory_bytes: 20448
#include<iostream>
using namespace std;
int main()
{
  long long int n,i;
  cin>>n;
  long long int sum=0;
  for(i=1;i<=n;i++)
  {
    if(i%3!=0 && i%5!=0)
      sum+=i;
  }
  cout<<sum;
  return 0;
}

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

int main(){
    int a, b, c;
 
    cin >> a >> b >> c;
 
    bool flag = true;
 
    if(a+b == c) flag = true;
    else if(a+c == b) flag = true;
    else if(b+c == a) flag = true;
    else flag = false;
 
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
 
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int,input().split()))
ans = []
while len(ans) < N:
    for i in range(len(B) - 1, -1, -1):
        num = i + 1
        if num == B[i]:
            B.pop(i)
            ans.append(num)
            break
        if i == 0:
            print(-1)
            exit()
ans = ans[::-1]
print(*ans, sep='\n')

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define ll long long
#define maxn 100005
using namespace std;
int arr[maxn];
int n,a,b;
bool check(ll mid) {
	ll base = ((ll)1e9 / b + 1 >= mid ? b * mid : 1e9) , dif = a - b;
	for(int i=1;i<=n;i++)
		if((ll)arr[i] > base)
			mid -= ((ll)arr[i] - base - 1) / dif + 1;
	return mid >= 0;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b;
	for(int i=1;i<=n;i++)
		cin >> arr[i];
	ll l = 1 , r = (ll)1e14 , mid;
	while(true) {
		if(r - l < 3) {
			for(mid=r;mid>=l && check(mid);mid--);
			mid++;
			break;
		}
		mid = (l+r)>>1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << mid << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;


template<typename T>
struct StronglyConnectedComponents{
	vector<vector<T>> g,rg;
	vector<T>vs,cmp;//1回目のdfsの帰り順の並び,トポロジカル順序
	vector<bool>used;
	int num;//強連結成分の個数

	StronglyConnectedComponents(const vector<vector<T>> &G):num(0){//"有向"グラフを渡す
		int v=G.size();
		g.resize(v);
		rg.resize(v);
		used.resize(v);
		cmp.resize(v,-1);
		for(int i=0;i<v;++i){
			for(auto e:G[i]){
				add_edge(i,e);
			}
		}
		for(int i=0;i<v;++i){
			if(!used[i]){
				dfs(i);
			}
		}
		reverse(vs.begin(),vs.end());
		for(int i=0;i<v;++i){
			if(cmp[vs[i]]==-1){
				rdfs(vs[i],num);
				num++;
			}
		}
	}

	void add_edge(int u,int v){
		g[u].emplace_back(v);
		rg[v].emplace_back(u);
	}

	void dfs(int v){
		used[v]=true;
		for(auto x:g[v]){
			if(!used[x]){
				dfs(x);
			}
		}
		vs.emplace_back(v);
	}

	void rdfs(int v,int num){
		cmp[v]=num;
		for(auto x:rg[v]){
			if(cmp[x]==-1)rdfs(x,num);
		}
	}
};

void solve(){
	int n,m;
	cin>>n>>m;
	vector<vector<int>>g(n);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		g[u].eb(v);
	}
	StronglyConnectedComponents<int>scc(g);
	vector<vector<int>>ans(scc.num);
	rep(i,n){
		ans[scc.cmp[i]].eb(i);
	}
	cout<<scc.num<<"\n";
	rep(i,scc.num){
		if(ans[i].size()){
			cout<<ans[i].size();
		}
		for(auto e:ans[i]){
			cout<<" "<<e;
		}
		cout<<"\n";
	}
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

#define rep(var,n)  for(int var=0;var<(n);++var)

void solve(string& s) {
    int L = s.size();
    rep(i, L-1) {
        if (s[i] == s[i+1]) {
            printf("%d %d\n", 1+i, 1+i+1);
            return;
        }
        if (i+2 < L && s[i] == s[i+2]) {
            printf("%d %d\n", 1+i, 1+i+2);
            return;
        }
    }
    printf("-1 -1\n");
}

int main() {
    string s; cin >> s;
    solve(s);
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>a>>b;
      Cout((a+b)/2);
     

       
return 0;
}



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

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

    bool con = false;

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '7')
            con = true;
    }

    if(con)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s;
  t = s;
  reverse(t.begin(), t.end());
  int count = 0;
  for (int i = 0; i < s.length()/2; i++)
  {
    if (s[i] != t[i])
    {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  /*freopen("input.txt", "r", stdin);
  freopen("op1.txt", "w", stdout);*/
  long long n;
  int k,count=0;
  string s;
  cin>>n;
  cin.ignore();
  cin>>s;
  int low=0;
  int high=n-1;
  while(low<=high){
  	if(s[low]!=s[high]&&s[low]=='W'){
  		swap(s[low],s[high]);
  		count++;
  	}
  	else if(s[low]==s[high]&&s[low]=='W'){
  		high--;
  	}
  	else{
  		low++;
  	}
  }
  cout<<count<<endl;
  
  return 0;
}

Measured memory_bytes: 3776
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,q = map(int,readline().split())

jinja = [-(10**10+10)]

for i in range(a):
    jinja.append(int(readline()))

tera = [-(10**10+10)]

for i in range(b):
    tera.append(int(readline()))

#add big number
jinja.append(2*10**10+10)
tera.append(2*10**10+10)

for query in range(q):
    x = int(readline())
    j_r = bisect.bisect_left(jinja,x)
    j_l = jinja[j_r-1]
    t_r = bisect.bisect_left(tera,x)
    t_l = tera[t_r-1]
    j_r = jinja[j_r]
    t_r = tera[t_r]
    ans = min((x-j_l)*2+(t_r-x),(x-t_l)*2+(j_r-x),(x-j_l)+(t_r-x)*2,(x-t_l)+(j_r-x)*2)
    ans = min (ans,x - min(j_l,t_l), max(j_r,t_r)-x)
    print(ans)

        




Measured memory_bytes: 137088
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e5+5;
char s[N];
int main(){
    long long cnt=0;
    scanf("%s",s+1);
    long long ans=0;
    int n=strlen(s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='B') cnt++;
        else ans+=cnt;
    }
    cout<<ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<algorithm> 
#include <cassert>
#include <string>
//#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f, eps = 0.001;
#define IO() assert(freopen("in.in", "rt", stdin)), assert(freopen("out.out", "wt", stdout))
#define ll long long int
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
void printar(int arr[], int n){
    for(int i = 0; i < n; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}
// template <typename... T>
// void debug(T &... args)
// {
//     ((cerr << args << " "), ...);
//     cerr << endl;
// } 
// struct COMPARE { 
//   bool operator()(pair<string,ll> const& P1, pair<string,ll> const& P2) 
//     { 
        
//         return P1.first < P2.second;
//     }  
// };
// priority_queue<pair<string,ll>,vector<pair<string,ll>>,COMPARE >pq;
int s(int n){
    int x;
    int x1 = 0, x2 = 0, x3 = 0;
    while(n)
    {
        x = n % 10;
        n /= 10;
        if(!(x == 3 || x == 4 || x ==  7)){
            return 0;
        }
        if(x == 3) x1++;
        if(x == 4) x2++;
        if(x == 7) x3++;
    }
    if(x1 && x2 && x3) return 1;
}

int ss(char c1, char c2, char c3){
    int x = 0;
    x += c1 - '0';
    x *= 10;
    x += c2 - '0';
    x *= 10;
    x += c3 - '0';
    return abs(x - 753);
}
int main()
{     
    // icpctraining
    // IO();
    FastIO();
    int a, b, c; cin >> a >> b >> c;
    if(a != b && a != c) cout << a;
    else if(b != a && b != c) cout << b;
    else if(c != a && c != b) cout << c;
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int W = scanner.nextInt();
    int H = scanner.nextInt();
    int x = scanner.nextInt();
    int y = scanner.nextInt();
    int r = scanner.nextInt();

    if (x-r<0||x+r>W||y-r<0||y+r>H){
      System.out.println("No");
    }
    if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
      System.out.println("Yes");
      }
  }
}



Measured memory_bytes: 26228
N = int(input())

def dfs(num):
    if int(num) > N:
        return 0

    # numが753数ならcntを1にセット
    cnt = 0
    flag = 1
    for i in "753":
        if not num.count(i):
            flag = 0
            break
    if flag:
        cnt += 1

    for i in "753":
        cnt += dfs(num + i)

    return cnt

print(dfs("0"))


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

string str;

int solve(int left, int right){
	// cout<<left<<" "<<right<<endl;
	// for(int i = left; i < right; i++){
		// cout<<str[i];
	// }cout<<endl;
	if(str[left] != '[') return (stoi(str.substr(left,right-left))+1)/2;
	
	int ans = 0;
	vector<int> temp;
	
	for(int i = left, j = left+1, con = 0; i < right; i++){
		if(str[i] == ']')con--;
		if(str[i] == '[')con++;
		
		if(con == 0){
			temp.push_back(solve(j,i));
			j = i+2;
		}
	}
	sort(temp.begin(),temp.end());
	
	for(int i = 0; i < (temp.size()+1)/2; i++){
		ans += temp[i];
	}
	// cout<<ans<<endl;
	return ans;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>str;
		
		cout<<solve(1,str.size()-1)<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define x first
#define y second
 
typedef long long ll;
typedef pair<int, int> PII;
 
const int N = 2e5 + 10;
const long long INF = (ll)1e18;
const double PI = acos(-1.0);
 
PII a, b, c[N];
int s[N];
 
int find(int n)
{
	int n1 = 0;
	for(int i = 0; i < n; i++){
		int t = lower_bound(s, s+n1, c[i].y) - s;
		s[t] = c[i].y;
		if(t == n1) n1++;
	}
	return n1;
}
 
int main ()
{
	scanf("%d %d %d %d", &a.x, &a.y, &b.x, &b.y);
	if(a.x > b.x) swap(a, b);
	int x1 = a.x, x2 = b.x, y1 = a.y, y2 = b.y;
	if(x1 > x2) swap(x1, x2);
	if(y1 > y2) swap(y1, y2);
	int n, n1 = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &c[n1].x, &c[n1].y);
		if(c[n1].x >= x1 && c[n1].x <= x2 && c[n1].y >= y1 && c[n1].y <= y2)
			n1++;
	}
	
	sort(c, c+n1);
	
	double ans = 0;
	if(x1 == x2 || y1 == y2){
		ans = (x2 - x1) * 100.0 + (y2 - y1) * 100.0 + n1 * (PI - 2.0) * 10;
	}else{
		if(a.y > b.y)
		for(int i = 0; i < n1; i++)
			c[i].y = a.y - c[i].y;
		int t = find(n1);
		if(t == x2 - x1 + 1 || t == y2 - y1 + 1) ans += PI * 5;
		ans += (x2 - x1) * 100.0 + (y2 - y1) * 100.0 + (5 * PI - 20.0) * t;
	}
	
	printf("%.12lf\n", ans);
	
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 12345678901234

int main(){
    ll i,j;
    ll n;
    cin>>n;
    ll M=-1;
    vector<ll> v(100,0);
    for(i=0;i<n;i++) {
        ll x;
        cin>>x;
        v[x]++;
        M=max(M,x);
    }
    ll m=100;
    for(i=0;i<=M;i++){
        ll s=max(i,M-i);
        m=min(m,s);
        v[s]--;
        if(v[s]<0){
            cout<<"Impossible"<<endl;
            return 0;
        }
    }
    for(i=0;i<=m;i++){
        if(v[i]>0){
            cout<<"Impossible"<<endl;
            return 0;
        }
    }
    cout<<"Possible"<<endl;


    return 0;
}

Measured memory_bytes: 384
def f(x):
  if x % 2 == 0:
    return x//2
  else:
    return 3*x+1

dic = {}
s = int(input())
dic[s] = 1
cnt = 1
while True:
  s = f(s)
  if s in dic.keys():
    print(cnt+1)
    break
  else:
    dic[s] = 1
    cnt += 1


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::string S){
    if (N <= 2) {
        cout << 0 << endl;
        return;
    }

    vector<vector<int>> sum(3, vector<int>(N+1));
    rep(i,1,N+1) {
        rep(j,0,3) {
            sum[j][i] += sum[j][i-1];
        }
        if (S[i-1] == 'R') sum[0][i]++;
        if (S[i-1] == 'G') sum[1][i]++;
        if (S[i-1] == 'B') sum[2][i]++;
    }
    ll answer = 0;
    rep(i,0,N) rep(j,i+1,N) {
        if (S[i] == S[j]) continue;
        if (S[i] != 'R' && S[j] != 'R') {
            answer += sum[0][N] - sum[0][j+1];
            int k = j + (j-i);
            if (k < N && S[k] == 'R') answer--;
        }
        if (S[i] != 'G' && S[j] != 'G') {
            answer += sum[1][N] - sum[1][j+1];
            int k = j + (j-i);
            if (k < N && S[k] == 'G') answer--;
        }
        if (S[i] != 'B' && S[j] != 'B') {
            answer += sum[2][N] - sum[2][j+1];
            int k = j + (j-i);
            if (k < N && S[k] == 'B') answer--;
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3720
package main

import "fmt"

func main() {
	var numA, numB int

	for {
		fmt.Scan(&numA)
		fmt.Scan(&numB)

		if numA == 0 && numB == 0 {
			break
		}

		if numA < numB {
			fmt.Println(numA, numB)
		} else {
			fmt.Println(numB, numA)
		}
	}
}



Measured memory_bytes: 1392
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <bitset>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<long long> VI;
typedef unsigned long long ull;
const ll inff = 0x3f3f3f3f3f3f3f3f;
#define FOR(i,a,b) for(int i(a);i<=(b);++i)
#define FOL(i,a,b) for(int i(a);i>=(b);--i)
#define SZ(x) ((long long)(x).size())
#define REW(a,b) memset(a,b,sizeof(a))
#define inf int(0x3f3f3f3f)
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define mod ll(998244353)
#define pb push_back
#define eps 1e-6
#define lc d<<1
#define rc d<<1|1
#define Pll pair<ll,ll>
#define P pair<int,int>
#define pi acos(-1)
int n,a[28],ans;
int main()
{
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    FOR(i,1,n) si(a[i]);
    FOR(i,2,n-1)
    {
        if(a[i]>a[i-1]&&a[i+1]>a[i]) ans++;
        if(a[i]<a[i-1]&&a[i+1]<a[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a[200010];
int ma1, ma2;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (ma1 < a[i]) {
			ma2 = ma1;
			ma1 = a[i];
		}
		else if (ma2 < a[i])ma2 = a[i];
	}
	rep(i, n) {
		if (a[i] == ma1)cout << ma2 << endl;
		else cout << ma1 << endl;
	}
}

Measured memory_bytes: 3200
// Aizu Vol-5 0569: Illumination
// 2017.9.4 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

int w, h;
char map[103][103], out[103][103];
int m[2][6][2] = {
	{{-1,-1},{0,-1},{-1,0},{1,0},{-1,1},{0,1}},
	{{0,-1},{1,-1},{-1,0},{1,0},{0,1},{1,1}}};

typedef struct { int x, y; } T;
T que[10003]; int top;

void outside()
{
	int i, k, x, y, x2, y2;

	que[0].x = 0, que[0].y = 0, out[0][0] = 2, top = 1;
	while (top > 0) {
		x = que[--top].x, y = que[top].y, k = y & 1;
		for (i = 0; i < 6; i++) {
			x2 = x + m[k][i][0], y2 = y + m[k][i][1];
			if (x2 >= 0 && x2 <= w+1 && y2 >= 0 && y2 <= h+1 && !out[x2][y2]) {
				if (map[x2][y2]) { out[x2][y2] = 1; continue; }
				out[x2][y2] = 2, que[top].x = x2, que[top].y = y2, top++;
			}
		}
	}
}

int check(int x, int y)
{
	int i, k, s, x2, y2;
	k = y & 1;
	for (s = 0, i = 0; i < 6; i++) {
		x2 = x + m[k][i][0], y2 = y + m[k][i][1];
		if (out[x2][y2] == 2) s++;
	}
	return s;
}

int main()
{
	int x, y, ans;
	
	scanf("%d%d", &w, &h);
	for (y = 1; y <= h; y++) for (x = 1; x <= w; x++) scanf("%d", &map[x][y]);
	outside();
	for (ans = 0, y = 1; y <= h; y++) for (x = 1; x <= w; x++)
		if (map[x][y]) ans += check(x, y);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  bool fg = false;
  int fi = n / 100;
  int sec = n / 10;
  int secsec = sec % 10;
  int thi = n % 10;  

  if (fi == 7 || secsec == 7 || thi == 7) {
    cout << "Yes" << endl;
  } else { cout << "No" << endl;}
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
  double x1,y1,x2,y2,x3,y3,x4,y4;
  while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
	      &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)){
    if( (x2-x1)*(x4-x3) + (y2-y1)*(y4-y3) == 0 ) printf("YES\n");
    else printf("NO\n");
  }
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n,m;
  cin>>n>>m;
  cout<<abs((n-2)*(m-2))<<endl;
  return 0;
}
/*
N == 1 && M == 1 ← 1回
N == 1 && M != 1 ← (M−2)回
N >= 2 のとき、N <= M → M ≥ 2、このとき
<i>四隅のカードは4回
<ii>それ以外の周上のカードは6回
<iii>それ以外のカードは9回
以上より、求める答えは(N−2)(M−2)回
*/

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

int main() {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	for (int i = 1; i <= B; i++) {
		int pls = A * i;
		if ((pls - C) % B == 0) {
			printf("YES");
			return 0;
		}
	}
	printf("NO");
}

Measured memory_bytes: 256
h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
A = {i:0 for i in range(10)}
for _ in range(h):
  for i in input().split():
    if i != '-1':
      A[int(i)] += 1
    

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][k] + c[k][j],c[i][j])
      

ans = 0
for i in range(10):
  ans += c[i][1] * A[i]
print(ans)




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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto&& ai : a) cin >> ai;
	sort(a.begin(), a.end());
	int maxcount = 1;
	int first = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - a[first] > 2)
		{
			maxcount = max(maxcount, i - first);
			first = lower_bound(a.begin(), a.end(), a[i]-2) - a.begin();
		}
	}
	maxcount = max(maxcount, n - first);
	cout << maxcount << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int) 1e5 + 7;
int n, m, k, a[N], b[N];


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

  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int ma = a[1], mb = b[1];
  for (int i = 2; i <= n; i++) ma = min(ma, a[i]);
  for (int i = 2; i <= m; i++) mb = min(mb, b[i]);
  int sol = ma + mb;
  for (int i = 1; i <= k; i++) {
    int x, y, d;
    cin >> x >> y >> d;
    sol = min(sol, a[x] + b[y] - d);
  }
  cout << sol << "\n";

}


Measured memory_bytes: 1024
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i != 1 and i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)


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

int main(){
	int i,j;
	int l[1000][3];
	int n;
	int tmp,t,sum;

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


	for(i=0;i<n;i++){
		tmp=0;
		t=0;
		sum=0;
		for(j=0;j<3;j++){
			if(tmp < l[i][j]){
				tmp = l[i][j];
				t = j;
			}
		}
		for(j=0;j<3;j++){
			if(j!=t){
				sum += (l[i][j]*l[i][j]);
			}
		}

		if(sum == (tmp*tmp)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
		
	}	

	return 0;
}

Measured memory_bytes: 588
data = list( input() )
n1 = int( data[0] + data[1] )
n2 = int( data [2] + data[3] )

if 1 <= n1 <= 12 and 1 <= n2 <= 12:
    print('AMBIGUOUS')
elif n1 == 0 and n2 == 0:
    print('NA')
elif 1 <= n1 <= 12:
    print('MMYY')
elif 1 <= n2 <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    bool dame[100001] = {};
    for(int i = 0;i<m;i++){
        int a;
        cin >> a;
        dame[a] = true; // a段目は壊れている
    }
    vector<int> dp(n+1);
    dp[0]= 1;
    for(int i = 0;i<=n;i++){
        if(dame[i]) continue;// 壊れてたらとばす
        if(i >= 1) dp[i] += dp[i-1];
        if(i >= 2) dp[i] += dp[i-2];
        dp[i] %= mod;
    }
    cout << dp[n] << endl; // dp.back()も可
}


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

int main(){
    int count=0;
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s.at(i)=='R'||s.at(i)=='U'||s.at(i)=='D'){
            count++;
            }
        }

        if(i%2==1){
            if(s.at(i)=='L'||s.at(i)=='U'||s.at(i)=='D')
            count++;
        }
    }


    if(count==s.size())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<P> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

int main() {
    ll N,W=0,H=0,ans = 0;
    bool flag = false;
    cin >> N;
    vl A(N);
    rep(i,N) cin >> A[i];

    sort(A.begin(), A.end(), greater<ll>());

    rep1(i,N){
        if(A[i] == A[i-1]){
            if(W == 0){
                W = A[i];
                i++;
                continue;
            }else{
                H = A[i];
                ans = H * W;
                break;
            }
        }
    }

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int prime[1000000];
int main(){
    prime[0]=-1;
    prime[1]=-1;
    for(int i=2;i<1000000;i++){
        if(prime[i]==0){
            prime[i]=1;
            for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
        }
    }
    int now;
    while(~scanf("%d",&now)){
        int ans=0;
        for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    ll n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n),c(n,inf);
    vector<vector<int>> b(200010,vector<int>(0));
    rep(i,n){
        int g;
        cin >> g;
        a.at(i)=g;
        b.at(g).push_back(i);
    }
    //return 0;
    ll u=0,t=0;
    while (true){
        int tt=t;
        if (c.at(t)!=inf) break;
        auto it=upper_bound(b.at(a.at(t)).begin(),b.at(a.at(t)).end(),t);
        if (it==b.at(a.at(t)).end()) {t=b.at(a.at(t)).at(0)+1;u++;}
        else t=*it+1;
        if (t==n) {t=0;u++;}
        c.at(tt)=t;
    }
    k=k%u;
    int y;
    if (k==0) {cout << endl;return 0;}
    while (true){
        y=t;
        if (t>=c.at(t) || t+1==c.at(t)) k--;
        if (k==0) break;
        t=c.at(t);
    }
    vector<int> r(0);
    while (true){
        
        //cout << y << " " << c.at(y) << endl;
        auto it=upper_bound(b.at(a.at(y)).begin(),b.at(a.at(y)).end(),y);
        if (it==b.at(a.at(y)).end()) {r.push_back(a.at(y));y++;}
        else y=*it+1;
        //cout << y << endl;
        if (y>=n || y==0) break;
    }
    if (r.size()==0) {cout << endl;return 0;}
    rep(i,r.size()-1) cout << r.at(i) << " ";
    cout << r.at(r.size()-1) << endl;
}

Measured memory_bytes: 16504
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

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







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 2000005
#define LL long long
#define P int(1e4+7)
using namespace std;

int x,a;

int main(){
	
	cin>>x>>a;
	if(x < a) cout<<0;
	else cout<<10;
	
	return 0;
}

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

int main(){
	string s;
	while(getline(cin,s)){
		int size=s.size();
		for(int j=0;;j++){
			string ex=s;
			rep(i,size){
				if(isalpha(ex[i])){
					ex[i]=(char)(((int)ex[i]-'a'+j)%26+'a');
				}
			}
			int cnt=0;
			rep(i,size-2){
				if(ex[i]=='t' && ex[i+1]=='h' && ex[i+2]=='e'){
					cnt++;
					s=ex;
					break;
				}
			}
			rep(i,size-3){
				if(ex[i]=='t' && ex[i+1]=='h' && (ex[i+2]=='i' || ex[i+2]=='a') && (ex[i+3]=='s' || ex[i+3]=='t')){
					cnt++;
					s=ex;
					break;
				}
			}
			if(cnt>=1)break;
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll h, w;
  scanf("%lld%lld", &h, &w);
  printf("%lld\n", (h + w) % 24);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
   for(;;){
       int n=sc.nextInt();
   if(n==0)break;
   int bank[]=new int[n];
   double nennri[]=new double[n];
   int y=sc.nextInt();
   for(int i=0; i<n; i++){
	   bank[i]=sc.nextInt();
	   double r=sc.nextDouble();
	   int t=sc.nextInt();
	   if(t==1)nennri[i]=1+y*r/100;
	   else{ nennri[i]=1;
		   for(int j=0;j<y;j++)nennri[i]*=(1+(r/100));}
   }
   double most=0; int mostb=0;
   for(int i=0;i<n;i++){
	   if(most<nennri[i]){
		   most=nennri[i]; mostb=bank[i];
	   }
   }
   System.out.println(mostb);
   }
   }
 } 

Measured memory_bytes: 50608
from collections import deque
N, M = map(int, input().split())
S = input()

# 頂点iがラベルA・Bの頂点といくつ隣接しているか
connect_label = [[0, 0] for i in range(N)]

# 削除する予定の頂点を管理するキュー
queue = deque()

# 削除済みの頂点を管理する集合
deleted_set = set()

# 各頂点の連結情報
G = [[] for i in range(N)]

# 辺の情報を入力
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    G[a].append(b)
    G[b].append(a)
    connect_label[a][1 - (S[b] == "A")] += 1
    connect_label[b][1 - (S[a] == "A")] += 1

# AまたはBのみとしか連結してないものをキューに追加
for i in range(N):
    if 0 in connect_label[i]:
        queue.append(i)

# キューが空になるまで削除を繰り返す
while queue:
    n = queue.pop()

    # すでに削除していれば何もしない
    if n in deleted_set:
        continue

    # 連結していた頂点について情報を書き換える
    for v in G[n]:
        connect_label[v][1 - (S[n] == "A")] -= 1
        # 未削除で、AまたはBのみとしか連結しなくなったものはキューに追加
        if (v not in deleted_set) and (0 in connect_label[v]):
            queue.appendleft(v)
        
    deleted_set.add(n)

# 全て削除していたらNo, そうでなければYes
print("Yes" if len(deleted_set) != N else "No")


Measured memory_bytes: 73632
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int A,B,K;
	cin>>A>>B>>K;
	
	set<int> S;
	
	for(int i=0;i<K;i++){
		S.insert(A+i);
		S.insert(B-i);
	}
	
	for(auto a:S){
		if(a>=A&&a<=B){
			cout<<a<<endl;
		}
	}
		
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (to_string(i).size() % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	cout << (n + 1) / 2 - 1;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B;
  cin >> A >> B;
  if (A + B == 3) {
    cout << 3 << endl;
  } else if (A + B == 4) {
    cout << 2 << endl;
  } else if (A + B == 5) {
    cout << 1 << endl;
  }
}


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

int a[100010];
int cnt[100010];

int main() {
	long long n, q, b, c, s=0;

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

	cin >> n;

	for(long long i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		s += a[i];
	}

	cin >> q;
	while(q--) {	//q operations
		cin >> b >> c;
		long long tmp = cnt[b]*(b-c);
		s = s - tmp;
		cnt[c] += cnt[b];
		cnt[b] = 0;

		cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 4348
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
start = []
goal = []
for i in ab:
  if i[0] == 1:
    start.append(i[1])
  elif i[1] == n:
    goal.append(i[0])
p = start + goal
if len(p) == len(list(set(p))):
  print('IMPOSSIBLE')
else:
  print('POSSIBLE')

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);

  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int l;
      cin >> l;
      l--;
      s[i].push_back(l);
    }
  }
  vector<int> p(m);

  rep(i, m) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool flg = true;
    for (int j = 0; j < m; ++j) {
      int con = 0;
      for (auto sm : s[j])
        if (i & (1<<sm)) con++;
      if (con % 2 != p[j]) flg = false;
        }
    if (flg) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
hs = [int(s) for s in input().split()]
dp = [0]*n
dp[0], dp[1] = 0, abs(hs[1]-hs[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs (hs[i] - hs[i-1]), dp[i-2] + abs(hs[i] - hs[i-2]))
print(dp[-1])

Measured memory_bytes: 13928
N,Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for i in range(Q)]

total = []
total.append(0)
for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        total.append(1)
    else:
        total.append(0)
totsum = 0
for idx, val in enumerate(total):
    totsum += val
    total[idx] = totsum

for lr in lrs:
    print(total[lr[1] - 1] - total[lr[0] - 1])



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

double Dis(double x1, double y1, double x2, double y2);
int main(void){
	while(1){
		int n;
		int ans = 1;
		vector< pair<double, double> > p;

		cin >> n;
		if(n == 0) break;

		for(int i=0; i<n; i++){
			pair<double, double> t;
			cin >> t.first >> t.second;
			p.push_back(t);
		}

		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				//中点
				double mpx = (p[i].first + p[j].first) / 2.0;
				double mpy = (p[i].second + p[j].second) / 2.0;
				//2点間の距離
				double d1 = Dis(p[i].first, p[i].second, p[j].first, p[j].second);
				if(d1 > 2.0) continue;
				//p[i]からp[j]へ向かうベクトル
				double v1x = (p[j].first - p[i].first) / d1;
				double v1y = (p[j].second - p[i].second) / d1;
				//中点から円の中心へ向かう単位ベクトル
				double v2x = -v1y;
				double v2y = v1x;
				//中心から円の中心へ向かうベクトルの長さ
				double d2 = sqrt(1.0 - (d1*d1/4.0));

				//円の中心の座標
				double cx = mpx + v2x * d2;
				double cy = mpy + v2y * d2;

				int cnt = 0;
				for(int k=0; k<n; k++){
					if(k == i || k == j || (cx-p[k].first)*(cx-p[k].first) + (cy-p[k].second)*(cy-p[k].second) <= 1.0)	cnt++;
				}
				if(cnt > ans){
					ans = cnt;
				}

				cx = mpx - v2x * d2;
				cy = mpy - v2y * d2;

				cnt = 0;
				for(int k=0; k<n; k++){
					if(k == i || k == j || (cx-p[k].first)*(cx-p[k].first) + (cy-p[k].second)*(cy-p[k].second) <= 1.0)	cnt++;
				}
				if(cnt > ans){
					ans = cnt;
				}
			}
		}

		cout << ans << endl;


	}
	
	return 0;
}

double Dis(double x1, double y1, double x2, double y2){
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

Measured memory_bytes: 1256
import java.util.Scanner;

//20180510
//02

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

		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int l = scanner.nextInt();
		long[][] a = new long[n][m];
		long[][] b = new long[m][l];
		long[][] c = new long[n][l];

		for(int x = 0;x < n;x++) {
			for (int y = 0; y < m; y++) {
				a[x][y] = scanner.nextLong();
			}
		}

		for(int x = 0;x < m;x++) {
			for (int y = 0; y < l; y++) {
				b[x][y] = scanner.nextLong();
			}
		}

		for(int x = 0;x < n;x++) {
			for (int y = 0; y < l; y++) {
				for (int z = 0; z < m; z++) {
					c[x][y] += a[x][z] * b[z][y];
				}
			}
		}

		for(int x = 0;x < n;x++) {
			for (int y = 0; y < l-1; y++) {
					System.out.printf("%d ",c[x][y]);
			}
			System.out.println(c[x][l-1]);
		}

		scanner.close();
    }
}


Measured memory_bytes: 69408
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int y, a, b;
	cin >> y;
	if (y == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
const int N=100005;
typedef pair<int,int> pi;
typedef set<int>::iterator sit;
int n,fa[N],cnt;
queue<pi> q;
set<int> G1[N],G2[N];
int find_father(int x){
	if(fa[x]==x)
        return x;
	return fa[x]=find_father(fa[x]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
        fa[i]=i;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G1[u].insert(v);
		G1[v].insert(u);
	}
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G2[u].insert(v);
		G2[v].insert(u);
		if(G1[u].find(v)!=G1[u].end())
            q.push(pi(u,v));
	}
	while(!q.empty()){
		int u=q.front().first,v=q.front().second;
		q.pop();
		u=find_father(u),v=find_father(v);
		if(u==v)
            continue;
		if(G1[u].size()+G2[u].size()>G1[v].size()+G2[v].size())
            swap(u,v);
		fa[u]=v;
		G1[u].erase(v);
		G1[v].erase(u);
		G2[u].erase(v);
		G2[v].erase(u);
		for(sit it=G1[u].begin();it!=G1[u].end();it++){
			int x=*it;
			G1[x].erase(u);
			G1[x].insert(v);
			G1[v].insert(x);
			if(G2[x].find(v)!=G2[x].end())
                q.push(pi(x,v));
		}
		for(sit it=G2[u].begin();it!=G2[u].end();it++){
			int x=*it;
			G2[x].erase(u);
			G2[x].insert(v);
			G2[v].insert(x);
			if(G1[x].find(v)!=G1[x].end())
                q.push(pi(x,v));
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(find_father(i)==i)
            cnt++;
	puts(cnt==1?"YES":"NO");
}


Measured memory_bytes: 29056
#include<cstdio>
#include<cstring>
using namespace std;
char inp[100005],s1[6]={'d','r','e','a','m',0},s2[8]={'d','r','e','a','m','e','r',0},s3[6]={'e','r','a','s','e',0},s4[7]={'e','r','a','s','e','r',0};
bool dp[100005];
char *ss[4]={s1,s2,s3,s4};
inline bool cmp(char *p1,char *p2,int len){
	while(len--){
		if(*p1!=*p2) return 0;
		p1++;
		p2++;
	}
	return 1;
}
inline int getv(int end){
	int xb,ret=0;
	for(xb=0;xb<4;xb++){
		int st=end-strlen(ss[xb])+1;
		if(st>=0 && cmp(&inp[st],ss[xb],strlen(ss[xb]))) ret|=(1<<xb); 
	}
	return ret;
}
int main(){
	scanf("%s",inp);
	int xb,len,x2;
	len=strlen(inp);
	for(xb=1;xb<len;xb++){
		int ret=getv(xb);
		for(x2=0;x2<4;x2++){
			if(ret&(1<<x2)){
				if(xb-strlen(ss[x2])==-1 || dp[xb-strlen(ss[x2])]){
					dp[xb]=1;
					break;
				}
			}
		}
	}
	printf("%s\n",(dp[len-1]?("YES"):("NO")));
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;





void solve(){
    int n;
    cin>>n;
    n *= (n*n);
    cout<<n;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
const ll MOD = 1e9+7;

vector< vector<ll> > matmul(vector< vector<ll> > a,vector< vector<ll> > b){
	vector< vector<ll> > ans(a.size(),vector<ll>(a.size(),0));
	ll n = a.size();
	FOR(i,0,n){
		FOR(j,0,n){
			FOR(k,0,n){
				(ans[i][j] += (a[i][k]*b[k][j])%MOD)%=MOD;
			}
		}
	}
	return ans;
}

void printmat(vector< vector<ll> > a){
	FOR(i,0,a.size()){
		FOR(j,0,a[i].size()){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

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

	ll N,K;
	cin >> N >> K;
	vector< vector<ll> > a(N,vector<ll>(N,0)),ans;
	ans = a;
	FOR(i,0,N){
		ans[i][i] = 1;
		FOR(j,0,N){
			cin >> a[i][j];
		}
	}

	while(K){
		if(K&1LL){
			ans = matmul(ans,a);
		}
		a = matmul(a,a);
		K = K/2;
	}
	ll sum = 0;
	FOR(i,0,N){
		FOR(j,0,N){
			sum = ( sum + ans[i][j] ) % MOD;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,Ma,Mb;
	cin >> N >> Ma >> Mb;
	int A[40],B[40],C[40];
	for(int i = 0;i < N;i++) {
		cin >> A[i] >> B[i] >> C[i];
	}
	int dp[41][401][401];
	for(int i = 0;i <= N;i++) {
		for(int j = 0;j <= 400;j++) {
			for(int k = 0;k <= 400;k++) {
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
	for(int i = 0;i < N;i++) {
		for(int j = 0;j <= 400;j++) {
			for(int k = 0;k <= 400;k++) {
				if(dp[i][j][k] == INF) {
					continue;
				}
				dp[i + 1][j][k] = min(dp[i + 1][j][k],dp[i][j][k]);
				dp[i + 1][j + A[i]][k + B[i]] = min(dp[i + 1][j + A[i]][k + B[i]],dp[i][j][k] + C[i]);
			}
		}
	}
	int ret = INF;
	for(int i = 1;i <= 400;i++) {
		for(int j = 1;j <= 400;j++) {
			if(i * Mb == j * Ma) {
				ret = min(ret,dp[N][i][j]);
			}
		}
	}
	if(ret == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ret << endl;
	}
}

Measured memory_bytes: 51712