akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[1111][1111], used[N], dp[N], ans, id[1111][1111], sz;
map <pii, int> num;
vector <int> g[N], gr[N], order;

inline int get (int x, int y) {
   if (!num.count ({x, y})) num[{x, y}] = ++ sz;
   return num[{x, y}];
}

void dfs (int v) {
   used[v] = 1;
   for (auto to : g[v]) {
      if (!used[to]) dfs (to);
      else if (used[to] == 1) cout << -1, exit (0);
   }
   used[v] = 2;
   order.pb (v);
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j < n; j ++) {
         cin >> a[i][j];
         int x = i, y = a[i][j];
         if (x > y) swap (x, y);
         id[i][j] = get (x, y);
         if (j > 1) g[id[i][j - 1]].pb (id[i][j]), gr[id[i][j]].pb (id[i][j - 1]);
      }
   for (int i = 1; i <= n * (n - 1) / 2; i ++)
      if (!used[i])
         dfs (i);
   memset (used, 0, sizeof used);
   reverse (all (order));
   for (auto v : order) {
      for (auto to : g[v])
         dp[to] = max (dp[to], dp[v] + 1);
   }
   cout << ++ *max_element (dp + 1, dp + n * (n - 1) / 2 + 1);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 128752
N, K = map(int, input().split())
m = 2 * N - 1

if 2 <= K < m:
    mid = list((3, 2, 1) if K == 2 else (K - 1, K, K + 1, K - 2))
    a = list(set(range(1, m + 1)) - set(mid))
    print("Yes\n" + "\n".join(map(str, a[:m//2 - 1] + mid + a[m//2 - 1:])))
else:
    print("No")


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

        public static void main(String[] args) throws java.io.IOException{
            Scanner scan = new Scanner(System.in);
            int [] w =new int [10];
            int [] k =new int [10];
            for(int i=0;i<10;i++)w[i]=scan.nextInt();
            for(int i=0;i<10;i++)k[i]=scan.nextInt();
            Arrays.sort(w);
            Arrays.sort(k);
            System.out.println((w[9]+w[8]+w[7])+" "+(k[9]+k[8]+k[7]));
        }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
  
map<long long int,long long int>dp;

long long int solve(long long int i)
{
    if(i==1)
        return 1;
    if(dp.find(i)==dp.end())
        dp[i]=1+2*solve(i/2);
    return dp[i];
}
int main()
{
    long long int h;
    cin>>h;
    cout<<solve(h); 
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif
using namespace std;

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
typedef unsigned char byte;
typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

const int MAXN = 100100;
int N, K;
int nums[MAXN];

int main()
{
    while (cin >> N >> K)
    {
        set<int> vals;
        FO (i, N)
        {
            cin >> nums[i];
            vals.insert(nums[i]);
        }
        if (vals.count(K))
        {
            cout << "POSSIBLE" << endl;
            continue;
        }
        int mi = *(vals.begin());
        int ma = *(--vals.end());
        while (vals.size() > 1)
        {
            set<int> nxt;
            for (auto it1 = vals.begin(), it2 = next(it1); it2 != vals.end(); it1 = it2++)
            {
                if (*it1 == 0)
                    continue;
                nxt.insert(*it2 % *it1);
            }
            swap(vals, nxt);
            if (*(vals.begin()) != 0)
                mi = min(mi, *(vals.begin()));
        }
        bool ok = false;
        FO (i, N)
        {
            if (nums[i] > K && (nums[i] - K) % mi == 0)
            {
                ok = true;
                break;
            }
        }
        cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    }
    return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
#include <climits>

typedef std::vector<int> liste;
typedef liste::const_iterator iter;

void print_array(liste list) {
    for(int i = 0; i < list.size(); ++i){
        if(i>0) std::cout << " ";
        std::cout << list[i];
    }
    std::cout << std::endl;
}

bool solve(int i,int m,liste& list) {
    if(m==0) {
        return true;
    }
    if(i>=list.size()) {
        return false;
    }
    int mprime = m-list[i];
    i++;
    bool res = (solve(i,m,list)||solve(i,mprime,list));
    return res;
} 
    
int main(void){
        
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int value;
    liste list,question;
    int n;
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        list.push_back(value);
    } 
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        question.push_back(value);
    } 

    for(int i=0; i<question.size(); i++) {
        if(solve(0,question[i],list)) {
            std::cout << "yes" << std::endl;            
        } else {
            std::cout << "no" << std::endl;            
        }
    } 
    
    return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 2e5 + 5 ;
using namespace std ;

struct poi {
	int l, r ;
} a[N] ;
int n, m, p[N], d[N], top, ans ;

bool cmp(poi a, poi b) {
	return a.l < b.l ;
}

void push(int x) {
	p[top ++] = x ;
	push_heap(p, p + top) ;
}

void pop() {
	pop_heap(p, p + top) ; -- top ;
}

int main() {
	scanf("%d%d", &n, &m) ;
	rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r) ;
	sort(a + 1, a + n + 1, cmp) ;
	top = 0 ;
	rep(i, 1, n) {
		if (top + 1 <= a[i].l) push(- a[i].r) ; else 
			if (!a[i].l) d[++ d[0]] = a[i].r ; else {
				if (- p[0] < a[i].r) d[++ d[0]] = - p[0], pop(), push(- a[i].r) ; else d[++ d[0]] = a[i].r ;
			}
	}
	sort(d + 1, d + d[0] + 1) ;
	int tmp = top ; top = m, ans = 0 ;
	for (int i = d[0] ; i; -- i) {
		if (d[i] <= top && top > tmp) -- top ; else ++ ans ;
	}
	printf("%d\n", ans) ;
	return 0 ; 
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;

typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int main(){
	int q;
	cin>>q;
	int y[3]={200,195,195};
	while(q--){
		int a,b,c;
		cin>>a>>b>>c;
		int out=c-1;
		loop(i,1,a)out+=y[i%3];
		if(a%3==0){
			out+=20*(b-1);
		}else{
			loop(i,1,b)if(i%2)out+=20;else out+=19;
		}
		cout<<196470-out<<endl;
	}
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 int main() {
   string a,b,c;
   char A,B,C;
   cin >> a >> b >> c;
   A=a.at(0);
   B=b.at(0);
   C=c.at(0);
   cout << A << B << C << endl;
   
}



Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 1e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
void prllP(pair<ll,ll> a){
	cout<<a.first<<" "<<a.second<<endl;
}
void addmul(ll& a,ll b){
	add_self(a,0);add_self(b,0);//a=a%mod;
	a*=b;
	add_self(a,0);
}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
vector<ll>v[nax];
vector<pair<ll,ll>> dp(nax ,{0LL,0LL});


pair<ll,ll> dfs(ll x, ll parent){
// if(dp[x] != make_pair(0LL,0LL))return dp[x];
pair<ll,ll> ans ={1,1} ;
for(auto child : v[x]){
	if(child!=parent)dfs(child,x);
}
ll res  = 1 ;
for(auto child:v[x]){
if(child == parent)continue ; 
addmul(ans.first , (dp[child].first + dp[child].second));
addmul(ans.second , dp[child].first);
}
return dp[x] = ans; 
// return ans;

}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n ; cin>>n;
for(ll i = 0 ; i<n -1; i++){
	ll a , b; cin>>a>>b;
	v[a].push_back(b);
	v[b].push_back(a);
}
dfs(1,-1);
ll res = (dp[1].first + dp[1].second)%mod;
cout<<res;	
}

Measured memory_bytes: 12800
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[100001];
int main()
{
	long long ans=0;int n,k;scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",a+i);sort(a+1,a+1+n);for(int i=1;i<=k;++i)ans+=a[i];printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;

int main() {

	vector<int> a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);

	int res = 3;
	sort(a.begin(), a.end());
	if (a.at(0) == a.at(1)) res--;
	if (a.at(1) == a.at(2)) res--;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ----------------------------------- "<<endl
#define LL long long
#define DB double
#define LDB long double
#define ULL unsigned long long
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	inline LL read(){
		LL nm=0; bool fh=true; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return fh?nm:-nm;
	}
} using namespace IO;
#define mod 998244353
namespace  CALC{
	inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
	inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
	inline int mul(int x,int y){return (LL)x*(LL)y%mod;}
	inline void upd(int &x,int y){x+=y;(x>=mod)?(x-=mod):0;}
	inline void dec(int &x,int y){x-=y;(x<0)?(x+=mod):0;}
	inline int qpow(int x,int sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;}
}using namespace CALC;
#define M 510
int n,m,t[M],tot;
char ch[M],*s;
LL ans;
int main(){
	scanf("%s",ch+1),n=strlen(ch+1),m=read();
	for(int i=1;i<=n;i++){
		if(i==1||ch[i]!=ch[i-1]) ++tot;
		++t[tot];
	}
	if(tot==1){printf("%lld\n",((LL)n*(LL)m)>>1);return 0;}
	for(int i=2;i<tot;i++) ans+=(t[i]>>1); ans*=m;
	if(ch[1]!=ch[n]) ans+=(LL)((t[1]>>1)+(t[tot]>>1))*(LL)m;
	else{
		ans+=((t[1]>>1)+(t[tot]>>1));
		ans+=(LL)((t[1]+t[tot])>>1)*(LL)(m-1);
	} printf("%lld\n",ans); return 0;
}

Measured memory_bytes: 256
//abc059_a.cpp
//Fri Oct 19 23:21:47 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	transform(a.begin(),a.end(),a.begin(),::toupper);
	transform(b.begin(),b.end(),b.begin(),::toupper);
	transform(c.begin(),c.end(),c.begin(),::toupper);

	cout << a[0] << b[0] << c[0] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long t,n,k,x,y,z,b,c;
    string ch,chi;
    cin >> ch >> chi;
    t=0;
    for(int i=0;i<ch.size();i++)
    {
        if(ch[i]!=chi[i])
        {
            t++;
        }
    }
    cout << t <<endl;
    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string S;
    cin>>S;

    if(S=="Sunny")cout<<"Cloudy\n";
    else if(S=="Cloudy")cout<<"Rainy\n";
    else cout<<"Sunny\n";

    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;++i) cin>>d[i];
    set<int> v;
    for(int i=0;i<n;++i){
        v.insert(d[i]);
    }
    cout<<v.size()<<endl;
    return 0;
}


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

int main(){
    long long int N;
    cin >> N;
    long long int ans = 0;
    for(int i = 1; i <= N; i++){
        if(i%3 != 0 && i%5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3568
#include <stdio.h>

int main() {
  int i,h;
  char s[4];
  char t[4];
    scanf("%s",s);
    scanf("%s",t);
  h=0;
  for (i = 0; i < 3; i++) {
    if (s[i]==t[i]) {
      h++;
    }
  }
  printf("%d\n",h);
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int N;
	cin >> N;

	int ans = N;

	while (ans > 0) {
		ans -= 1000;
	}

	cout << abs(ans) << endl;

	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
      	int K = sc.nextInt();
      	int Q = sc.nextInt();
      	
      	int[] b = new int[N];	
      
      for(int i=0;i<Q;i++){
        int win = sc.nextInt();
        b[win-1] = b[win-1] + 1;
       }
      
      for(int i=0;i<N;i++){
      
        if(b[i]>Q-K){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
      
	}
}

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

const double Pi = acos(-1) ;

int main () {
  double a , b , c ;
  cin >> a >> b >> c ;
  double ans1 , ans2 ,ans3 ;
  ans1 = a * b * sin(c/180*Pi) / 2 ;
  ans2 = a + b + sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c/180*Pi)) ;
  ans3 = ans1 * 2 / a ;
  printf("%1f\n",ans1);
  printf("%1f\n",ans2);
  printf("%1f\n",ans3);
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

bool is_prime(ll n) {
  for(ll i=2;i*i<=n;i++) {
    if(n%i==0) {
      return false;
    }
  }
  return n!=1;
}

int main() {
  ll n;
  cin >> n;
  vec ans(n);
  ll tmp=6;
  for(ll i=0;i<n;i++) {
    while(!is_prime(tmp)) {
      tmp+=5;
    }
    ans[i]=tmp;
    tmp+=5;
  }
  for(ll i=0;i<n;i++) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int q=sc.nextInt();
    Node[] a = new Node[n];
    for(int i=0;i<n;i++){
      a[i]=new Node();
    }
    for(int i=0;i<n-1;i++){
      int aa=sc.nextInt()-1;
      int bb=sc.nextInt()-1;
      a[aa].es.add(bb);
      a[bb].es.add(aa);
    }
    for(int i=0;i<q;i++){
      a[sc.nextInt()-1].v+=sc.nextInt();
    }
    Deque<Node> dq = new ArrayDeque<>();
    dq.addFirst(a[0]);
    a[0].d=true;
    while(!dq.isEmpty()){
      Node hr=dq.pollFirst();
      hr.d=true;
      for(int t:hr.es){
        if(!a[t].d){
          a[t].v+=hr.v;
          dq.addFirst(a[t]);
        }
      }
    }
    for(int i=0;i<n-1;i++){
      System.out.print(a[i].v+" ");
    }
    System.out.println(a[n-1].v);
  }
  static class Node{
    boolean d=false;
    int v=0;
    List<Integer> es = new ArrayList<>();
  }
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    string s;
    cin >> s;
    if(s[1]=='B'){
        c("ARC");
    }else{
        c("ABC");
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

ll MAX = 1e6+3;
ll MOD = MAX;
vector<ll> inv(MAX);
vector<ll> prod(MAX);

int calcInv() {
    inv[0] = -1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        inv[i] = (inv[MOD % i] * (MOD / i)) % MOD;
        inv[i] = (-1 * inv[i] + MOD) % MOD;
    }
    return 0;
}

int calcProd() {
    prod[0] = -1;
    prod[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        prod[i] = (prod[i - 1] * i) % MOD;
    }
    return 0;
}

ll calcExp(int a, int m) {
    ll i = 0;
    ll ans = 1;
    ll temp = a;
    while ( m > 0 ) {
        if ( m % 2 == 1 ) ans = (ans * temp) % MOD;
        temp = (temp * temp) % MOD;
        m /= 2;
    }
    
    return ans;
}

int main() {

    CIN(int, Q);
    vector<ll> x(Q);
    vector<ll> d(Q);
    vector<ll> n(Q);

    for (int i = 0; i < Q; i++) {
        cin >> x[i] >> d[i] >> n[i];
    }

    calcInv();
    calcProd();

    for (int i = 0; i < Q; i++) {
        if ( d[i] == 0 ) {
            cout << calcExp(x[i], n[i]) << "\n";
        } else {
            ll xd = (x[i] * inv[d[i]]) % MOD;
            if ( xd + (n[i] - 1) >= MAX || xd == 0 ) {
                cout << "0\n";
            } else if ( xd == 1 ) {
                cout << prod[xd + (n[i] - 1)] << "\n";
            } else {
                ll s, e, ans;
                s = prod[xd - 1];
                e = prod[xd + (n[i] - 1)];
                ans = (e * inv[s]) % MOD;
                ans = (ans * calcExp(d[i], n[i])) % MOD;
                cout << ans << "\n";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 18816
{-# OPTIONS_GHC -O3 #-}
{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}

import qualified Data.ByteString as B (getLine)
import qualified Data.ByteString.Char8 as C (readInt, words, unpack, reverse, dropWhile)
import qualified Data.Maybe as M (fromJust)
import Data.Char as C (isSpace)
import Data.List as L (elem)

readInt = fst . M.fromJust . C.readInt
rstrip = C.reverse . C.dropWhile C.isSpace . C.reverse

main = do
    (C.unpack . rstrip -> xxs) <- B.getLine
    putStrLn $ if '9' `elem` xxs then "Yes" else "No"


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	printf("%d %d %d\n",x,y,z);
	return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

struct bit{
   ll val[N];
   void init(){
      memset(val,0x3f,sizeof val);
   }
   void upd(int x,ll v){
      for(;x < N;x += (x&(-x)))val[x] = min(val[x],v);
   }
   inline ll query(int x){
      ll res = 0x3f3f3f3f3f3f3f3fLL;
      for(;x;x -= (x&(-x)))res = min(res,val[x]);
      return res;
   }
}s;

struct query{
   int l,r,c;
   inline bool operator < (const query &b) const {
      return r < b.r;
   }
}q[N];

int n,m;
ll f[N];
int main(){
   scanf("%d%d",&n,&m);
   fr(i,1,m){
      scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].c);
   }
   sort(q+1,q+m+1);

   s.init();
   s.upd(n,0);
   fr(i,1,m){
      f[i] = q[i].c+s.query(n+1-q[i].l);
      s.upd(n+1-q[i].r,f[i]);
   }
   ll w = s.query(1);
   if(w == inf)puts("-1");
   else printf("%lld\n",w);
   return 0;
}


Measured memory_bytes: 2944
n, k = map(int, input().split())
s = list(input())

cnt = 0
for i in range(n - 1):
    if s[i] == "R" and s[i + 1] == "L":
        cnt += 2
if s[0] == "L":
    cnt += 1

if s[-1] == "R":
    cnt += 1

happy = n - cnt

print(min(happy + k * 2, n - 1))


Measured memory_bytes: 49392
#include<cstdio>
char s[3], _s[3];
bool flag=true;
int main() {
	scanf("%c%c%c", &s[0], &s[1], &s[2]);
	getchar();
	scanf("%c%c%c", &_s[0], &_s[1], &_s[2]);
	for(int i=0; i<3; i++) if(s[i]!=_s[2-i]) flag=false;
	if(flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

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

const int MOD = 1e9 + 7;

void add_self(int& a, int b)
{
	a += b;
	if (a >= MOD)
	{
		a -= MOD;
	}
}

void sub_self(int& a, int b)
{
	a -= b;
	if (a < 0)
	{
		a += MOD;
	}
}



int main()
{

	FAST_IO;

	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, K = mis()
    v = [0]
    for i in range(N+1):
        v.append(v[-1]+i)
    ans = 0
    for k in range(K, N+2):
        mi = v[k] - v[0]
        ma = v[-1] - v[-1-k]
        ans += ma - mi + 1
        ans %= N1097
    print(ans)



main()



Measured memory_bytes: 20204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define foi(i,a,n) for(ll i=a;i<n;i++)
#define el "\n"
#define ll long long int
const int INF = 2e9+5;
void solve(){
	ll n,W;cin>>n>>W;
  	vector<ll> w(n),v(n),mx(W+1,0);
  	rep(i,n)cin>>w[i]>>v[i];
  	rep(i,n){
    	for(ll j=W-w[i];j>=0;j--){
        	mx[w[i]+j]=max(mx[w[i]+j], mx[j]+v[i]);
        }

    }
  	cout<<*max_element(mx.begin(),mx.end())<<el;
}

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

Measured memory_bytes: 4028
use proconio::input;

// use std::f64::consts::PI;
// use std::cmp::*;
// use std::collections::*;
// use proconio::marker::Chars;
const MOD: u64 = 1000000007;

fn main() {
    input! {
        n: usize,
        k: u64,
        A: [u64;n]
    }
    let mut onecnt = vec![0; 41];

    for i in 0..41 {
        for a in A.iter().clone() {
            if a & (1 << i) > 0 {
                onecnt[i] += 1;
            }
        }
    }
    //let r = (k as f64).log2() as u64 + 1;
    let mut minflg = false;
    let mut xor_v: u64 = 0;
    for i in (0..41).rev() {
        if 1 << i > k {
            continue;
        }
        let mut sel = 0;

        if onecnt[i as usize] < n - onecnt[i as usize] {
            if minflg || k & (1 << i) > 0 {
                sel = 1;
            }
        }
        if !minflg {
            if k & (1 << i) > 0 && sel == 0 {
                minflg = true;
            }
        }
        xor_v += sel << i;
    }
    let mut ans = 0;
    for a in A {
        ans += a ^ xor_v;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int main()
{
	int M,D;
	cin>>M>>D;
	int ans=0;
	for(int i=22;i<=D;i++)
	{
		if(i%10<2)continue;
		int x=i/10,y=i%10;
		if(x*y<=M)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 100002

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool b;
char ch;
ll n,a[N],first;

inline void read(ll &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n);
	rep(i,1,n)read(a[i]);
	sort(a+1,a+n+1);
	rrp(i,n,1)if(a[i]==a[i+1])
	{
		if(b)
		{
			printf("%lld",first*a[i]);
			return 0;
		}
		else
		{
			b=true;
			first=a[i];
			a[i]=-1;
		}
	}
	printf("0");
	return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
s = n.times.map { gets.to_i }
list = [-1]
debug = nil
s.each{|a|
  puts " " if debug
  p "a = #{a}" if debug
  p "list = #{list}" if debug
  # a???list???????°???????????°????????????°?????????????¬????a???
  if list.last < a # list????????????a???????°?????????£??????
    p "if : #{list} << #{a}" if debug
    list << a # list???a????????????, ??¨??????????¢???????
  else # ????°?????¬???\??????a???????????§??????????´????????????°a??¨???????????????
    p "else : i = -2" if debug
    i = -2 # ????????????2??????????????????
    while i >= -list.size and list[i] >= a # ????´?????????????????????????, 
      p "while : #{i} >= #{-list.size} and #{list[i]} >= #{a}" if debug
      i -= 1 # list(?????????????????§??????)????????§a??????????°?????????´????????¢???
      p "i = #{i}" if debug
    end
    p "serch result" if debug
    p i if debug
    i = (0...list.size).bsearch{ |x| list[x] >= a } - 1
    p i if debug
    if list[i] < a and list[i + 1] > a # a???????????§???????????????????????????
      p "if : #{list[i]} < #{a} and #{list[i + 1]} > #{a}" if debug
      list[i + 1] = a
    end
  end
  p list if debug
}
puts list.size - 1

Measured memory_bytes: 10388
use std::cmp;
fn main(){
    let (x, _n) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut ws = s.split_whitespace();
        let x: i32 = ws.next().unwrap().parse().unwrap();
        let n: i32 = ws.next().unwrap().parse().unwrap();
        (x, n)
    };
    let mut vec: Vec<i32> = Vec::new();

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let ws = s.split_whitespace();

    for v in ws {
        let t: i32 = v.parse().unwrap();
        vec.push(t);
    }

    let mut i = 0;
    loop {
        let mut flag_a = false;
        let mut flag_b = false;
        let mut ans_a: i32 = 0;
        let mut ans_b: i32 = 0;

        let t1 = x + i;
        if !vec.contains(&t1) {
            ans_a = t1.abs();
            flag_a = true;
        }

        let t2 = x - i;
        if !vec.contains(&t2) {
            ans_b = t2.abs();
            flag_b = true;
        }

        if flag_a && !flag_b {
            println!("{}", ans_a);
            return
        } else if !flag_a && flag_b {
            println!("{}", ans_b);
            return
        } else if flag_a && flag_b {
            println!("{}", cmp::min(ans_a, ans_b));
            return
        }
        i += 1;
    }
}


Measured memory_bytes: 2124
using System;
using System.Linq;

namespace AltCoder
{
    public sealed class A_Frog1
    {
        public static void Main()
        {
            long N = Convert.ToInt32(Console.ReadLine());
            long[] heights = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt64(x)).ToArray();

            long[] d = new long[N];
            d[0] = 0;
            d[1] = Math.Abs(heights[1] - heights[0]);

            for (long i = 2; i < N; i++)
            {
                d[i] = Math.Min(d[i - 1] + Math.Abs(heights[i] - heights[i - 1]),
                                d[i - 2] + Math.Abs(heights[i] - heights[i - 2]));
            }

            Console.WriteLine(d[N - 1]);
        }
    }
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005, INF = 0x3f3f3f3f;

int n, a[N];

struct State {
	int v0, p0, p1, a;

	int operator [] (int k) {
		return k <= p0 ? v0 : (k <= p1 ? v0 - 1 : k <= a ? v0 - 2 : INF);
	}

	int calc(int na, int i, int j) {
		return (*this)[i] + (i - j > 0) + (i - j > a - na);
	}

	int get(int na, int i) {
		return std::min({calc(na, 0, i), calc(na, p0 + 1, i), calc(na, p1 + 1, i)});
	}

	State trans(int na) {
		State g;
		g.a = na, g.v0 = get(na, 0);
		int l, r;
		l = 0, r = na;
		while (l <= r) {
			int md = (l + r) >> 1;
			if (get(na, md) == g.v0) {
				g.p0 = md;
				l = md + 1;
			} else {
				r = md - 1;
			}
		}
		g.p1 = g.p0;
		l = g.p0 + 1, r = na;
		while (l <= r) {
			int md = (l + r) >> 1;
			if (get(na, md) == g.v0 - 1) {
				g.p1 = md;
				l = md + 1;
			} else {
				r = md - 1;
			}
		}
		return g;
	}
};

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	State f;
	f.v0 = 0, f.p0 = f.p1 = f.a = 0;
	for (int i = 1; i <= n; ++i) {
		f = f.trans(a[i]);
	}
	f = f.trans(0);
	print(f[0]);
}


Measured memory_bytes: 6488
import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()

    val vst = Array(n) { -1 }

    val al = Array(n) { mutableListOf<Pair<Int, Int>>() }

    for (i in 1 until n) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        val w = sc.nextInt() % 2

        al[u].add(v to w)
        al[v].add(u to w)
    }

    fun op(i: Int, d: Int) {
        if (vst[i] != -1) {
            return
        }
        vst[i] = d % 2
        for (c in al[i]) {
            op(c.first, d + c.second)
        }
    }
    op(0, 0)

    println(vst.joinToString("\r\n"))
}


Measured memory_bytes: 125732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int n,k;
	cin>>n>>k;
	map<int,int> mp;
	for(int i=0; i<k; i++)
	{
		int d;
		cin>>d;
		for(int j=0;j<d;j++)
		{
			int a;
			cin>>a;
			mp[a] = i+1;
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(!mp[i]) sum++;
	}
	cout<<sum<<endl;
	return 0;
}





Measured memory_bytes: 3636
a, b = tuple(input().split())


def judge():
    def sub_judge1():
        if a == 'H':
            return True
        else:
            return False
    def sub_judge2():
        if b == 'H':
            return True
        else:
            return False

    if sub_judge2():
        return sub_judge1()
    else:
        return not sub_judge1()


if judge():
    print('H')
else:
    print('D')


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line []=br.readLine().split(" ");
		int n=Integer.parseInt(line[0]);
		int k=Integer.parseInt(line[1]);

		int ans =k;
		for(int i=1;i<n;i++) {
			ans*=(k-1);
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int i =0;
	
	int min = 1000000, max = -100000 ;
	long s = 0;
	if (n == 1)
	{
		int x;
		cin>>x;
		cout<<x<<" "<<x<<" "<<x<<endl;
	}
	else
	{
		while (i < n)
		{
			int x;
			cin>>x;
			if (x < min)
				min = x;
			if (max < x )
				max = x;
			i++;
			s = s + x;
		}
		cout<<min<<" "<<max<<" "<<s<<endl;
	}
	return 0;
}

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

x_list = []
y_list = []

# 証言の数のリスト
A_list = []


# 入力処理
for n in range(N):
    # 各人が持ってる証言の数
    A = int(input())
    A_list.append(A)
    x = []
    y = []
    for a in range(A):
        x_tmp, y_tmp = map(int, input().split())
        x.append(x_tmp)
        y.append(y_tmp)
    x_list.append(x)
    y_list.append(y)


# 正直者（仮定）のリスト
# Falseで初期化　みんな不親切だと仮定する
isHonest_list = [False] * N

# 解候補のリスト
ans_candidate = []

# 全探索
def dfs(i, isHonest_list, ans_candidate):
    # 正直者・不親切の仮定が矛盾しないかどうか判定する
    # 矛盾しない場合、解候補のリストに正直者の人数を追加する
    if i >= N:
        isNotContradict = True  # 矛盾しないと仮定する
        for n in range(N):
            # 人iが不親切という仮定のときは証言を考慮しない
            if isHonest_list[n] == False:
                continue
            # 正直（仮定）な人iの各証言を考慮
            for A_list_i in range(A_list[n]):
                # 正直な人（仮定）なのに不親切な人のことを正直者、
                # もしくは正直者のことを不親切と証言してたら矛盾する
                if (y_list[n][A_list_i] == 1 and isHonest_list[x_list[n][A_list_i]-1] == False) or\
                    (y_list[n][A_list_i] == 0 and isHonest_list[x_list[n][A_list_i]-1]):
                    isNotContradict = False
                    break
            else:
                continue
            break

        # 矛盾しないとき
        if isNotContradict:
            ans_candidate.append(isHonest_list.count(True))
        return

    # 不親切な人であると仮定する
    isHonest_list[i] = False

    dfs(i+1, isHonest_list, ans_candidate)
    
    # 正直者であると仮定する
    isHonest_list[i] = True
    dfs(i+1, isHonest_list, ans_candidate)

dfs(0, isHonest_list, ans_candidate)
print(max(ans_candidate))

Measured memory_bytes: 3480
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;
const ll INF = 2e9 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 3e5 + 10;

int a[N];
ll dp[N];

void solve() {
    int n;
    cin >> n;
    fr(i, n)
        cin >> a[i];

    fill(dp + 1, dp + n + 1, INF);
    fr(i, n) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
    cout << dp[n - 1];
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 1536
s = input()
t = input()
time = 0
if s == t:
	print("Yes")
while s != t:
	tmp = s[-1]
	s = tmp + s
	s = s[:-1]
	time += 1
	if s == t:
		print("Yes")
		break
	if time >= len(s):
		print("No")
		break
	
    

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

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)    _for (__VA_ARGS__)
#define rep(i,n)    FOR(i, size_t{}, n)
#define ALL(x)      begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr int64_t inf = 2e18;
constexpr size_t invalid = ~0ull;
constexpr size_t dy [] = {-1ull, 0, 1, 0};
constexpr size_t dx [] = {0, -1ull, 0, 1};

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

  size_t H, W;
  cin >> H >> W;
  vector <vector <char>> s (H, vector <char> (W));
  rep (i, H) rep (j, W) cin >> s[i][j];

  using P = pair <size_t, size_t>;
  vector <P> valid_paths;

  rep (i, H) rep (j, W)
  {
    if (s [i][j] == '.') valid_paths.emplace_back (i, j);
  }

  auto is_path = [&] (size_t y, size_t x)
  {
    try
    {
      return s.at (y).at (x) == '.';
    }
    catch (const out_of_range &)
    {
      return false;
    }
  };

  auto bfs = [&] (const P & start)
  {
    vector <vector <bool>> visited (H, vector <bool> (W, false));
    queue <pair <P, ll>> q;
    auto update = [&] (const P & p, ll cost)
    {
      size_t y, x;
      tie (y, x) = p;
      visited [y][x] = true;
      q.emplace (p, cost);
    };
    update (start, 0);
    ll maxcost = 0;
    while (not q.empty ())
    {
      auto now = q.front (); q.pop ();
      P pos;
      ll cost;
      size_t y, x;
      tie (pos, cost) = now;
      tie (y, x) = pos;

      maxcost = max (maxcost, cost);

      rep (direction, 4)
      {
        size_t ny = y + dy [direction];
        size_t nx = x + dx [direction];
        if (is_path (ny, nx) && not visited [ny][nx])
        {
          update (P {ny, nx}, cost + 1);
        }
      }
    }
    return maxcost;
  };

  ll ans = 0;
  for (auto && elem : valid_paths)
  {
    ans = max (ans, bfs (elem));
  }
  cout << ans << endl;
}


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

int a[50], b[50], c[50], d[50];
int n, m, q;
int ans = 0;
int arr[10];

void f(int idx, int low) {
  if (idx == n) {
    int value = 0;
    for (int i=0; i<q; i++) {
      if (arr[b[i]] - arr[a[i]] == c[i]) {
        value += d[i];
      }
    }
    ans = max(value, ans);
    return;
  }
  for (int i=low; i<=m; i++) {
    arr[idx] = i;
    f(idx+1, i);
  }
}
int main() {
  cin>>n>>m>>q;
  for (int i=0; i<q; i++) {
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    --a[i];
    --b[i];
  }
  f(0, 1);
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
z = list()
d = list()
y = 0
r,c = map(int,input().split())
for i in range(r):
    a = list(map(int,input().split()))
    b = sum(a)
    a.append(b)
    z.append(a)
    b = 0
for i in range(c+1):
    for j in range(r):
        y += z[j][i] 
    d.append(y)
    y = 0    
z.append(d)

for i in range(1,r+2):
    for j in range(1,c+2):
        if j == c+1:
            print(f"{z[i-1][j-1]}",end="")
        else:
            print(f"{z[i-1][j-1]}",end=" ")
    print()


Measured memory_bytes: 6232
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
#define pred(x) ((x)-1)
#define succ(x) ((x)+1)
//============================================================================
long stored_fibona, lastx;
long fibona(short n)
{
    printf("enter %d\n", n);
    if (!n)
        n++;
    if (n<4)
        stored_fibona=n;
    else
        stored_fibona=fibona(n-1)+fibona(n-2);
    printf("n=%d\t%ld\n", n, stored_fibona);
    return stored_fibona;
}
//----------------------------------------------------------------------------
long fibonb(short n)
{
    long i,o,m;

    if (!n)
        n++;
    if (n<4)
        return n;
    for (i=3,o=m=1; i<=n; i++){
         if (o<m)
            o=o+m;
         else
            m=o+m;
    }
    return o+m;
}
//----------------------------------------------------------------------------
void input(FILE *file)
{
    short n; char buffer[20];

    fgets(buffer, sizeof(buffer)-1, file);
    sscanf(buffer, "%hd", &n);
    //for (n=0; n<45; n++)
        printf("%ld\n", fibonb(n));
}
//============================================================================
#ifndef DESKTOP
int main()
{
    input(stdin);
    return 0;
}
#endif

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int s = int.Parse(Console.ReadLine());

                int sum = s, max = s;

                for (int i = 1; i < n; i++)
                {
                    int a = int.Parse(Console.ReadLine());

                    sum = Math.Max(sum + a, a);
                    max = Math.Max(max, sum);
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9224